javascript--processing (get) browser version, operating system

Source: Internet
Author: User

javascript--processing (get) browser version, operating system

/** * Created by Administrator on 15-1-12.*/functionBroswerutil () {}broswerutil= {    //Detecting Browser versionsGetbrowserversion:function () {        varAgent =navigator.userAgent.toLowerCase (); vararr = []; varBrowser = ""; varbversion = ""; varVerinnum = ""; //IE        if(Agent.indexof ("MSIE") > 0) {            varRegstr_ie =/msie [\d.] +;/gi; Browser= "IE"; Bversion= "" +Agent.match (Regstr_ie)}//Firefox        Else if(Agent.indexof ("Firefox") > 0) {            varREGSTR_FF =/firefox\/[\d.] +/gi; Browser= "Firefox"; Bversion= "" +Agent.match (REGSTR_FF); }        //Chrome        Else if(Agent.indexof ("Chrome") > 0) {            varRegstr_chrome =/chrome\/[\d.] +/gi; Browser= "Chrome"; Bversion= "" +Agent.match (regstr_chrome); }        //Safari        Else if(Agent.indexof ("Safari") > 0 &&Agent.indexof ("Chrome") < 0) {            varRegstr_saf =/version\/[\d.] +/gi; Browser= "Safari"; Bversion= "" +Agent.match (REGSTR_SAF); }        //Opera        Else if(Agent.indexof ("opera") >= 0) {            varRegstr_opera =/version\/[\d.] +/gi; Browser= "Opera"; Bversion= "" +Agent.match (Regstr_opera); } Else {            varBrowser =Navigator.appname; if(Browser = = "Netscape") {                varVersion = Agent.split (";"); varTrim_version = Version[7].replace (/[]/G,""); varRVSTR = Trim_version.match (/[\d\.]/g). ToString ();varRV = Rvstr.replace (/[,]/g, ""); Bversion=RV; Browser= "IE"}} verinnum= (bversion + ""). Replace (/[^0-9.) /ig, "");        Arr.push (Browser);        Arr.push (Verinnum); returnarr; },    //detects if the browser is xxWB: (function () {        varUserAgent =navigator.userAgent.toLowerCase (); return{isIE6:/msie 6.0/.test (useragent),//IE6IsIE7:/msie 7.0/.test (useragent),//IE7IsIE8:/msie 8.0/.test (useragent),//IE8IsIE9:/msie 9.0/.test (useragent),//IE9ISIE10:/msie 10.0/.test (useragent),//IE10ISIE11:/msie 11.0/.test (useragent),//IE11ISLB:/lbbrowser/.test (useragent),//Cheetah BrowserISUC:/ucweb/.test (useragent),//UC Browseris360:/360se/.test (useragent),//360 BrowserIsbaidu:/bidubrowser/.test (useragent),//Baidu BrowserIssougou:/metasr/.test (useragent),//Sogou BrowserIschrome:/chrome/.test (Useragent.substr (-33, 6)),// Chrome browser Isfirefox:/firefox/.test (useragent),//Firefox BrowserIsopera:/opera/.test (useragent),//Opera BrowserIssafire:/safari/.test (useragent) &&!/chrome/. Test (useragent),//Safire BrowserISQQ:/qqbrowser/.test (useragent)//QQ Browser        }; })(),    //detecting the current operating systemCurrentsystem: (function () {        varsystem ={win:false, Mac:false, XLL:false, iphone:false, Ipoad:false, ipad:false, iOS:false, Android:false, Nokian:false, winmobile:false, Wii:false, PS:false        }; varUA =navigator.useragent; //Testing Platform        varp =Navigator.platform; System.win= P.indexof (' Win ') = = 0; System.mac= P.indexof (' Mac ') = = 0; System.xll= (P.indexof (' Xll ') = = 0 | | p.indexof (' Linux ')) = = 0); //Detecting 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;  Case' 6.2 ': System.win= ' 8 ';  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)/i.test (UA)) {System.win= ' Phone '; System.winmobile= parsefloat (regexp[' $ ']); }        }        //Detecting iOS versions        if(System.mac && ua.indexof (' Mobile ') >-1) {            if(/cpu (?: IPhone)? OS (\d+_\d+)/i.test (UA)) {System.ios= parsefloat (regexp[' $ '].replace (' _ '), ‘.‘)); } Else{System.ios= 2;//can't really detect it, soonly Guess}} //Detect Android version        if(/android (\d+\.\d+)/i.test (UA)) {system.android= parsefloat (regexp[' $ ']); }        //Game SystemSystem.wii = Ua.indexof (' wii ') >-1; System.ps=/playstation/i.test (UA); return{System:system}}) ()}

javascript--processing (get) browser version, operating system

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.