How to find operating system in the client machine using JavaScript?

To detect the operating system on the client machine, you can use

  • navigator.appVersion
  • navigator.userAgent property

The Navigator appVersion property is a read-only property and it returns a string that represents the version information of the browser.

<script
function operatingSytem() { 
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
// Display the OS name
document.getElementById("OS").innerHTML = OSName;
</script

 

 

JavaScript Interview Questions with Answers [ Best 50+ ]

JavaScript interview questions are gathered for people who are applying for JS jobs. JavaScript was created by Brendan Eich in… Read More

4 years ago