How do I use JavaScript to detect what operating system someone is using?
Created May 4, 2012
Omar Khan Try this JavaScript code :-)
<SCRIPT LANGUAGE="JavaScript"> >!-- function checkOS() { if(navigator.userAgent.indexOf('Linux') != -1) { var OpSys = "Linux"; } else if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('95') != -1)) { var OpSys = "Windows95"; } else if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('NT') != -1)) { var OpSys = "Windows NT"; } else if(navigator.userAgent.indexOf('Win') != -1) { var OpSys = "Windows 3.1"; } else if(navigator.userAgent.indexOf('Mac') != -1) { var OpSys = "Macintosh"; } else { var OpSys = "operating system not recognised"; } return OpSys; } var OpSys = checkOS(); alert("Your operating system is: " + OpSys); //--> </SCRIPT>