JavaScript Operating System detection

The Window.navigator read-only property provides access to the Navigator object, enabling inquiries about the executing application. By referencing the navigator.appVersion string, one can identify the client's operating system.

However, it's important to recognize that relying solely on this string may lead to inconsistencies or inaccuracies due to user-agent spoofing or variations across different browsers. Therefore, while this approach offers insights into the operating system, it's advisable to consider additional methods and techniques for more reliable and robust operating system detection.

run this source code Browser View

Find Your Operating System

<!DOCTYPE html> <html> <head> <title>OS Examples</title> <script> function findOS() { var curOS="Not Nmaed..."; if (navigator.appVersion.indexOf("Win")!=-1) curOS="Windows"; if (navigator.appVersion.indexOf("Mac")!=-1) curOS="MacOS"; if (navigator.appVersion.indexOf("X11")!=-1) curOS="UNIX"; if (navigator.appVersion.indexOf("Linux")!=-1) curOS="Linux"; alert('Your OS: '+curOS); } </script> </head> <body> <h2>Find Your Operating System</h2> <p> <input type="button" value="Find Operating System" onclick="findOS()" /> </p> </body> </html>


JavaScript operating system detection involves utilizing the Window.navigator property, particularly the navigator.appVersion string, to glean insights about the user's operating system. This method offers a way to identify the operating system on the client side. However, due to potential inaccuracies arising from user-agent variations, it's recommended to complement this approach with other strategies for more dependable and comprehensive operating system detection.