How to detect operating system on the client machine using JavaScript ?
To detect the operating system on the client machine, one can simply use navigator.appVersion or navigator.userAgent property.
The Navigator appVersion property is a read-only property and it returns a string which represents the version information of the browser.
Syntax
navigator.appVersion
Example 1: This example uses navigator.appVersion property to display the operating system name.
<!DOCTYPE html> <html> <head> <title> How to detect operating system on the client machine using JavaScript ? </title> </head> <body style="text-align:center;"> <h1 style="color:green;">GeeksforGeeks</h1> <button ondblclick="operatingSytem()"> Return Operating System Name </button> <p id="OS"></p> <!-- Script to display the OS name --> <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> </body> </html> |
Output:
- Before Click on the Button:

- After Click on the Button:

Example 2: This example uses navigator.appVersion property to display all the properties of the client machine.
<!DOCTYPE html> <html> <head> <title> How to detect operating system on the client machine using JavaScript ? </title> </head> <body style="text-align:center;"> <h1 style="color:green;">GeeksforGeeks</h1> <button ondblclick="version()"> Return OS Version </button> <p id="OS"></p> <!-- Script to return OS details --> <script> function version() { var os = navigator.appVersion; // Display the OS details document.getElementById("OS").innerHTML = os; } </script> </body> </html> |
Output:
- Before Click on the Button:

- After Click on the Button:

Recommended Posts:
- Detect the Operating System of User using JavaScript
- How to get the client timezone offset in JavaScript?
- Detect a device is iOS or not using JavaScript
- How to detect browser or tab closing in JavaScript ?
- How to detect flash is installed or not using JavaScript ?
- How to detect touch screen device using JavaScript?
- Functions of Operating System
- How to detect the device is an Android device using JavaScript ?
- How to get the MAC and IP address of a connected client in PHP?
- PHP | Determining Client IP Address
- How to detect escape key press using jQuery?
- How to detect when user scrolls to the bottom of a div ?
- How to detect the user's device using jQuery ?
- How to detect a mobile device in jQuery?
- JQuery | Detect a textbox content is changed or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



