The Wayback Machine - https://web.archive.org/web/20240118182715/https://www.geeksforgeeks.org/how-to-detect-operating-system-on-the-client-machine-using-javascript/
Open In App
Related Articles

How to detect operating system on the client machine using JavaScript ?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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 that represents the version information of the browser. 

Syntax

navigator.appVersion

Example 1: This example uses the navigator.appVersion property to display the operating system name. 

html




<!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() {
            let 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 the navigator.appVersion property to display all the properties of the client machine. 

html




<!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() {
            let 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:


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 24 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials