laPistola Posted December 29, 2008 Share Posted December 29, 2008 anyone got a decent script that detects the clients OS and version ? ie displays something like: Windows XP looking around the internet and there is nothing really decent? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/138801-detect-os/ Share on other sites More sharing options...
rhodesa Posted December 30, 2008 Share Posted December 30, 2008 not that i'm aware of. you can get almost all the way there with jQuery: $.browser.OS() Quote Link to comment https://forums.phpfreaks.com/topic/138801-detect-os/#findComment-725899 Share on other sites More sharing options...
laPistola Posted December 30, 2008 Author Share Posted December 30, 2008 this is what i have for broswer detection, it also has OS detect at the bottom but its to basic var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i=0;i<data.length;i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) return data[i].identity; } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); }, dataBrowser: [ { string: navigator.userAgent, subString: "Chrome", identity: "Chrome" }, { string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "Version" }, { prop: window.opera, identity: "Opera" }, { string: navigator.vendor, subString: "iCab", identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror" }, { string: navigator.userAgent, subString: "Firefox", identity: "Firefox" }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { // for newer Netscapes (6+) string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" }, { string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" }, { // for older Netscapes (4-) string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" } ], dataOS : [ { string: navigator.platform, subString: "Win", identity: "Windows" }, { string: navigator.platform, subString: "Mac", identity: "Mac" }, { string: navigator.platform, subString: "Linux", identity: "Linux" } ] }; BrowserDetect.init(); im not to bothered about more details on the Mac or Linux OS but its important for the windows one to say 95,98,ME,XP,Vista is there any dom nodes that will get the information i need?? Quote Link to comment https://forums.phpfreaks.com/topic/138801-detect-os/#findComment-726151 Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 I was Googling around and found this script for you. It's a bit lengthy but it seems to work. <br /> <!--<br /> var os, ua = navigator.userAgent;<br /> if (ua.match(/Win(dows )?NT 6\.0/)) {<br /> os = "Windows Vista"; // Windows Vista ???<br /> }<br /> else if (ua.match(/Win(dows )?NT 5\.2/)) {<br /> os = "Windows Server 2003"; // Windows Server 2003 ???<br /> }<br /> else if (ua.match(/Win(dows )?(NT 5\.1|XP)/)) {<br /> os = "Windows XP"; // Windows XP ???<br /> }<br /> else if (ua.match(/Win(dows)? (9x 4\.90|ME)/)) {<br /> os = "Windows ME"; // Windows ME ???<br /> }<br /> else if (ua.match(/Win(dows )?(NT 5\.0|2000)/)) {<br /> os = "Windows 2000"; // Windows 2000 ???<br /> }<br /> else if (ua.match(/Win(dows )?98/)) {<br /> os = "Windows 98"; // Windows 98 ???<br /> }<br /> else if (ua.match(/Win(dows )?NT( 4\.0)?/)) {<br /> os = "Windows NT"; // Windows NT ???<br /> }<br /> else if (ua.match(/Win(dows )?95/)) {<br /> os = "Windows 95"; // Windows 95 ???<br /> }<br /> else if (ua.match(/Mac|PPC/)) {<br /> os = "Mac OS"; // Macintosh ???<br /> }<br /> else if (ua.match(/Linux/)) {<br /> os = "Linux"; // Linux ???<br /> }<br /> else if (ua.match(/(Free|Net|Open)BSD/)) {<br /> os = RegExp.$1 + "BSD"; // BSD ????<br /> }<br /> else if (ua.match(/SunOS/)) {<br /> os = "Solaris"; // Solaris ???<br /> }<br /> else {<br /> os = "N/A"; // ???? OS ???<br /> }<br /> document.write(os);<br /> // --><br /> Quote Link to comment https://forums.phpfreaks.com/topic/138801-detect-os/#findComment-726179 Share on other sites More sharing options...
laPistola Posted December 30, 2008 Author Share Posted December 30, 2008 Its the shortest code i seen for this yet and has Vista in it. perfect thank you very much, i was googling for hours and found nothing usful Quote Link to comment https://forums.phpfreaks.com/topic/138801-detect-os/#findComment-726194 Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 Here's the source. Although it's not in English, not sure what language it is. Quote Link to comment https://forums.phpfreaks.com/topic/138801-detect-os/#findComment-726202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.