complete user agent string detection script, including detection presentation engine, platform, Windows OS, mobile devices, and game systems
VaR client = function () {// rendering engines var engine = {ie: 0, Gecko: 0, WebKit: 0, khtml: 0, opera: 0, // complete Version ver: NULL}; // browsers var browser = {// browsers ie: 0, Firefox: 0, Safari: 0, konq: 0, opera: 0, chrome: 0, Safari: 0, // specific Version ver: NULL}; // platform/device/OS var system = {win: false, Mac: false, X11: false, // mobile devices iPhone: false, iPod: false, NOK IAN: false, winmobile: false, macmobile: false, // game systems Wii: false, PS: false}; // detect rendering engines/browsers var UA = navigator. useragent; If (window. opera) {engine. ver = browser. ver = Window. opera. version (); Engine. opera = browser. opera = parsefloat (engine. ver);} else if (/applewebkit \/(\ s + )/. test (UA) {engine. ver = Regexp ["$1"]; engine. webKit = parsefloat (engine. ver); // figure ou T if it's chrome or safari if (/chrome \/(\ s + )/. test (UA) {browser. ver = Regexp ["$1"]; browser. chrome = parsefloat (browser. ver);} else if (/version \/(\ s + )/. test (UA) {browser. ver = Regexp ["$1"]; browser. safari = parsefloat (browser. ver);} else {// approximate version var safariversion = 1; if (engine. webKit <100) {safariversion = 1;} else if (engine. webKit <312) {safariversion = 1.2;} else if (Engine. webKit <412) {safariversion = 1.3;} else {safariversion = 2;} browser. safari = browser. ver = safariversion;} else if (/khtml \/(\ s + )/. test (UA) |/Konqueror \/([^;] + )/. test (UA) {engine. ver = browser. ver = Regexp ["$1"]; engine. khtml = browser. konq = parsefloat (engine. ver);} else if (/RV :( [^ \)] +) \) Gecko \/\ D {8 }/. test (UA) {engine. ver = Regexp ["$1"]; engine. gecko = parsefloat (engine. ve R); // determine if it's Firefox if (/Firefox \/(\ s + )/. test (UA) {browser. ver = Regexp ["$1"]; browser. firefox = parsefloat (browser. ver) ;}} else if (/MSIE ([^;] + )/. test (UA) {engine. ver = browser. ver = Regexp ["$1"]; engine. ie = browser. ie = parsefloat (engine. ver);} // detect browsers browser. ie = engine. IE; browser. opera = engine. opera; // detect platform var P = navigator. platform; system. win = P. I Ndexof ("win") = 0; system. MAC = P. indexof ("Mac") = 0; system. x11 = (P = "X11") | (P. indexof ("Linux") = 0); // detect Windows operating systems if (system. win) {If (/WIN (?: Dows )? ([^ Do] {2}) \ s? (\ D + \. \ D + )? /. Test (UA) {If (Regexp ["$1"] = "NT") {Switch (Regexp ["$2"]) {Case "5.0": system. win = "2000"; break; Case "5.1": system. win = "XP"; break; Case "6.0": system. win = "vista"; break; default: system. win = "NT"; break;} else if (Regexp ["$1"] = "9x") {system. win = "me";} else {system. win = Regexp ["$1"] ;}}// mobile devices system. iPhone = UA. indexof ("iPhone")>-1; system. iPod = UA. indexof ("iPod")>-1; system. nokian = UA. indexof ("nokian")>-1; system. winmobile = (system. win = "CE"); system. macmobile = (system. iPhone | system. iPod); // gaming systems system. wii = UA. indexof ("wii")>-1; system. PS =/playstation/I. test (UA); // return it return {Engine: Engine, browser: browser, system: System };}();