JavaScript-client-side detection

Source: Internet
Author: User

"JavaScript advanced Programming" down, detection of rendering engine, platform, operating system, mobile device, game system detection script.

varClient =function(){    //Rendering Engines    varEngine ={ie:0, Gecko:0, WebKit:0, khtml:0, Opera:0,        //Complete versionVerNULL      }; //Browsers    varBrowser = {                //Browsersie:0, Firefox:0, Safari:0, Konq:0, Opera:0, Chrome:0,        //Specific VersionVerNULL    }; //Platform/device/os    varsystem ={win:false, Mac:false, X11:false,                //Mobile DevicesIphone:false, ipod:false, ipad:false, iOS:false, Android:false, Nokian:false, winmobile:false,                //Game SystemsWii:false, PS:false     }; //Detect Rendering Engines/browsers    varUA =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["$"]; Engine.webkit=parsefloat (Engine.ver); //Figure out if it ' s Chrome or Safari        if(/chrome\/(\s+)/. Test (UA)) {Browser.ver= regexp["$"]; Browser.chrome=parsefloat (Browser.ver); } Else if(/version\/(\s+)/. Test (UA)) {Browser.ver= regexp["$"]; Browser.safari=parsefloat (Browser.ver); } Else {            //approximate version            varSafariversion = 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["$"]; Engine.khtml= Browser.konq =parsefloat (Engine.ver); } Else if(/RV: ([^\)]+) \) gecko\/\d{8}/. Test (UA)) {Engine.ver= regexp["$"]; Engine.gecko=parsefloat (Engine.ver); //determine if it ' s Firefox        if(/firefox\/(\s+)/. Test (UA)) {Browser.ver= regexp["$"]; Browser.firefox=parsefloat (Browser.ver); }    } Else if(/msie ([^;] +)/. Test (UA)) {Engine.ver= Browser.ver = regexp["$"]; engine.ie= browser.ie =parsefloat (Engine.ver); }        //Detect Browsersbrowser.ie =engine.ie; Browser.opera=Engine.opera; //Detect Platform    varp =Navigator.platform; System.win= P.indexof ("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 (?:d ows)? ([^do]{2}) \s? (\d+\.\d+)?. Test (UA)) {            if(regexp["$"] = = "NT"){                Switch(regexp["$"]){                     Case"5.0": System.win= "2000";  Break;  Case"5.1": System.win= "XP";  Break;  Case"6.0": System.win= "Vista";  Break;  Case"6.1": System.win= "7";  Break; default: System.win= "NT";  Break; }                                        } Else if(regexp["$"] = = "9x") {System.win= "ME"; } Else{System.win= regexp["$"]; }        }    }        //Mobile DevicesSystem.iphone = Ua.indexof ("iphone") >-1; System.ipod= Ua.indexof ("IPod") >-1; System.ipad= Ua.indexof ("IPad") >-1; System.nokian= Ua.indexof ("Nokian") >-1; //Windows Mobile    if(System.win = = "CE") {System.winmobile=System.win; } Else if(System.win = = "Ph")){        if(/windows Phone OS (\d+.\d+)/. Test (UA))            {; System.win= "Phone"; System.winmobile= Parsefloat (regexp["$"]); }    }            //Determine IOS version    if(System.mac && ua.indexof ("Mobile") >-1){        if(/cpu (?: IPhone)? OS (\d+_\d+)/. Test (UA)) {System.ios= Parsefloat (Regexp.$1.replace ("_", "."))); } Else{System.ios= 2;//can ' t really detect-so guess        }    }        //Determine Android version    if(/android (\d+\.\d+)/. Test (UA)) {system.android= Parsefloat (regexp.$1); }        //Gaming SystemsSystem.wii = Ua.indexof ("Wii") >-1; System.ps=/playstation/i.test (UA); //return it    return{engine:engine, browser:browser, System:system};} ();

JavaScript-client-side detection

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.