How to Detect Operating System of User in Browser Using Vanilla Javascript Full Project For Beginners

How to Detect Operating System of User in Browser Using Vanilla Javascript Full Project For Beginners

 

Welcome folks today in this blog post we will be detecting the operating system of user in browser using vanilla javascript. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to make an index.html file and copy paste the following code

 

 

index.html

 

 

<!DOCTYPE HTML>
<html>

<head>
    <title>
        JavaScript
    | Detecting the Operating System of User.
    </title>
</head>

<body style="text-align:center;" id="body">
    <h1 style="color:green;">
            GeeksForGeeks
        </h1>
    <p id="GFG_UP"
    style="font-size: 19px;
            font-weight: bold;">
    </p>
    <button onclick="GFG_Fun()">
        click here
    </button>
    <p id="GFG_DOWN"
    style="color: green;
            font-size: 24px;
            font-weight: bold;">
    </p>
    <script>
        HTMLDocument.prototype.e = document.getElementById;
        var el_up = document.e("GFG_UP");
        var el_down = document.e("GFG_DOWN");
        el_up.innerHTML = "Click on the button to get the OS of User's System.";
        var Name = "Not known";
        if (navigator.appVersion.indexOf("Win") != -1) Name =
        "Windows OS";
        if (navigator.appVersion.indexOf("Mac") != -1) Name =
        "MacOS";
        if (navigator.appVersion.indexOf("X11") != -1) Name =
        "UNIX OS";
        if (navigator.appVersion.indexOf("Linux") != -1) Name =
        "Linux OS";

        function GFG_Fun() {
            el_down.innerHTML = Name;
        }
    </script>
</body>

</html>

 

See also  Javascript Tutorial to Validate Indian Voter ID Number Format Using Regular Expression in Browser Full Project For Beginners

 

And now if you open the index.html file inside the browser you will see the below screenshot

 

 

Leave a Reply