get system type in javascript

To get the system type (whether the system is Windows, MacOS, or Linux), you can use the navigator.platform property in JavaScript. Here's an example code snippet:

index.tsx
let systemType;

if(navigator.platform.indexOf("Win") != -1){
  systemType = "Windows";
} else if(navigator.platform.indexOf("Mac") != -1){
  systemType = "MacOS";
} else if(navigator.platform.indexOf("Linux") != -1){
  systemType = "Linux";
} else {
  systemType = "Unknown";
}

console.log(systemType); // prints "Windows", "MacOS", "Linux", or "Unknown"
357 chars
14 lines

This code checks the value of navigator.platform for the presence of "Win", "Mac", and "Linux" to determine the system type. If none of these are found, the system type is set to "Unknown".

related categories

gistlibby LogSnag