Detecting the Operating System in JavaScript

var system = navigator.appVersion; if (navigator.appVersion.indexOf("Mac") != -1 ) OS = "Mac"; else if (navigator.appVersion.indexOf("PowerPC") != -1 ) OS = "Mac"; else if (navigator.appVersion.indexOf("Win") != -1 ) OS = "Win"; else if (navigator.appVersion.indexOf("SunOS") != -1 ) OS = "Solaris"; else OS = "Linux"; //Determine Browser Version bName = navigator.appName; bVer = parseInt(navigator.appVersion); if (OS == "Mac" && bName=="Netscape") { // your code here } else if (OS =="Mac" && bName=="Microsoft Internet Explorer") { // your code here } else if (OS =="Win" || OS == "Linux" && bName == "Netscape") { // your code here } else if (OS =="Solaris" && bName=="Netscape") { // your code here } else if (OS =="Win" || OS == "Linux" && bName=="Microsoft Internet Explorer") { // your code here }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.