Detect the Operating System of User using JavaScript Last Updated : 19 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The task is detect the operating system of User with the help of JavaScript. we're going to discuss few techniques. Approach: Access the navigator.appVersion or navigator.userAgent property. Get the index of the OS using indexOf() method. If index is other than -1, then it is the OS, that we are looking for. Example 1: In this example, navigator.appVersion property is used to get the OS. 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> Output: Before clicking on the button: After clicking on the button: Example 2: In this example, navigator.userAgent property is used to get the OS. 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> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); el_up.innerHTML = "Click on the button to get the OS of User's System."; var Name = "Unknown OS"; if (navigator.userAgent.indexOf("Win") != -1) Name = "Windows OS"; if (navigator.userAgent.indexOf("Mac") != -1) Name = "Macintosh"; if (navigator.userAgent.indexOf("Linux") != -1) Name = "Linux OS"; if (navigator.userAgent.indexOf("Android") != -1) Name = "Android OS"; if (navigator.userAgent.indexOf("like Mac") != -1) Name = "iOS"; function GFG_Fun() { el_down.innerHTML = Name; } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Comment More infoAdvertise with us Next Article Detect the Operating System of User using JavaScript P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads 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 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.appVersionExample 1: This example uses th 2 min read How to Detect Keypress using JavaScript ? In this article, keyboard detection is performed using HTML and CSS. HTML stands for "Hypertext Markup Language". HTML language helps the developer to create and design web page elements like links, sections, paragraphs, headings, and blockquotes for web applications. CSS stands for "Cascading Style 2 min read How to detect the user's device using jQuery ? The task is to determine the user's device, whether it is iPad or not, using JQuery. Below are the required methods: Navigator userAgent Property: This property returns the value of the header of user-agent which is sent by the browser to the server. Returned value, have information like name, versi 1 min read How to detect the browser language preference using JavaScript ? Detecting the language preferences of users can be very important for Websites or Web Apps to increase user interaction. In JavaScript, this task can be easily done by using the Languages property available for the navigator interface. The navigator.language and the navigator.languages property toge 2 min read How to detect touch screen device using JavaScript? Sometimes you might be looking for some features to include into your web-app that should only be available to devices with a touch screen. You may need this detection while introducing newer smarter controls for touch screen users in the game app or a GPS and navigation application. While there are 3 min read Like