zoukankan      html  css  js  c++  java
  • [转载] javascript 浏览器类型

    -----------------------------------------------------------------------------
    browserinfo.js #
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    
    // from: http://hao.360.cn/zt/browserinfo.html
    if(!window.console)
    {
        console = {};
        console.log = function(){
            alert(Array.prototype.slice.call(arguments));
        };
    }
    var browserDetector = (function(){
        // Useragent RegExp
        var rwebkit = /(webkit)[ \/]([\w.]+)/,
        ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
        rmsie = /(msie) ([\w.]+)/,
        rsafari = /(safari)[ \/]([\w.]+)/,
        rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
        rfirefox = /(firefox)[ \/]([\w.]+)/,
        rtrident = /(trident)[ \/]([\w.]+)/,
        rgecko = /(gecko)[ \/]([\w]+)/,
        rchrome = /(chrome)[ \/]([\w.]+)/,
        rpresto = /(presto)[ \/]([\w.]+)/,
        rshell = /(maxthon|360se|360ee|theworld|se|theworld|greenbrowser|mqqbrowser|qqbrowser|tencenttraveler)[ \/]?([\w.]*)/,
        //device
        randroid = /(android)[ \/]([\w.]+)/,
        ripad = /(ipad)(?:.*os)? ([\d_]+)/,
        riphone = /(iphone)(?:.*os)? ([\d_]+)/,//untested
        //ripod = /(ipod)(?:.*os)? ([\d_]+)/,//untested
        roperamini = /(opera mini)[ \/]([\w.]+)/,//untested
        rblackberry = /(blackberry)([\d]+)/,//untested
        rnokia = /(nokia)([\w]+)[ \/]///untested
        rsymbian = /(symbianos)[ \/]([\w.]+)(?:.*)(series60)[ \/]([\w.]+)?///untested
        rwinmob = /(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/,//untested
        noneDouble=["",""],noneTriple = ["","",""];
        return function(ua){
            var info = {};
            //core----------
            var core = rchrome.exec( ua ) ||
                rsafari.exec( ua ) ||
                ropera.exec( ua ) ||
                rmsie.exec( ua ) ||
                rfirefox.exec( ua ) ||
                ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
                noneTriple;
            //shell----------
            var shell = rshell.exec( ua )||noneTriple,
                the360se = function(){
                    try{
                        var is360se = external.twGetRunPath.toLowerCase().indexOf("360se")>-1?true:false;
                        if(is360se)
                        {
                            try{
                                var version = external.twGetVersion(external.twGetSecurityID(window));
                                return ["360se",version];
                            }catch(e){
                                return ["360se","-"];
                            }
                        }
                        return noneDouble;
                    }catch(e){return noneDouble;}
                }(),
                theMaxthon = function() {
                    try {
                        if (/(\d+\.\d)/.test(external.max_version)) {
                            return ["maxthon",parseFloat(RegExp['\x241'])];
                        }
                        return noneDouble;
                    } catch (e) {return noneDouble;}
                }();
            //layout engine----------
            var layout = rtrident.exec( ua ) ||
                rwebkit.exec( ua ) ||
                rgecko.exec( ua ) ||
                rpresto.exec( ua ) || noneTriple;
            //device----------
            var device = randroid.exec(ua)||
                riphone.exec(ua)||
                ripad.exec(ua)||
                roperamini.exec(ua)||
                rblackberry.exec(ua)||
                rnokia.exec(ua)||
                noneTriple;
            if(!device[1]){
                var winmob = rwinmob.exec(ua);
                if(winmob){
                    device = ["","Windows Smartphone",""];
                }else{
                    device = ["","Desktop","full capability browser"];
                }
            }else if(device[1]==="android"){
                device = [device[0],"Mobile device","android "+device[2]];
            }else if(device[1]==="ipad"||device[1]==="iphone"){
                device[2] = "IOS "+device[2].replace(/_/g,".");
            }else if(device[1]==="nokia"){
                var symbian = rsymbian.exec(ua);
                if(symbian)
                    device = ["",device[1]+device[2],"("+symbian[1]+"/"+symbian[2]+" "+symbian[3]+"/"+symbian[4]+")"];
                else
                    device = ["",device[1]+device[2],""];
            }
            //-----------
            info.layout = [layout[1],layout[2]];
            info.core = [core[1],core[2]];
            info.shell = [shell[1],shell[2]];
            if(the360se[0]){
                info.shell = the360se;
            } else if(theMaxthon[0]) {
                info.shell = theMaxthon;
            }
            info.script = function(){
                if(core[1]==="msie"){
                    try{
                        return [ScriptEngine(),[ScriptEngineMajorVersion(),ScriptEngineMinorVersion(),ScriptEngineBuildVersion()].join(".")];
                    }catch(e){
                        return noneDouble;
                    }
                }else{
                    return noneDouble;
                }
            }();
            info.documentMode = document.documentMode;
            info.browserMode = function(){
                if(browserMode===7){
                    if(layout[2]=="5.0"){
                        browserMode += " (IE9兼容模式)"
                    }else if(core[2]=="8.0"||layout[2]=="4.0"){
                        browserMode += " (IE8兼容模式)"
                    }
                }
                return browserMode;
            }();
            info.compatMode = document.compatMode;
            info.device = [device[1],device[2]];
            return info;
        };
    })();
        
    (function(){
        var info = browserDetector(navigator.userAgent.toLowerCase()),
            _d = function(id){return document.getElementById(id);};
        _d("browserCore").innerHTML = info.core.join(" / ");
        _d("layoutEng").innerHTML = info.layout.join(" / ");
        _d("scriptEng").innerHTML = info.script.join(" / ");
        _d("compatMode").innerHTML = info.compatMode;
        _d("browserShell").innerHTML = info.shell.join(" / ");
        _d("device").innerHTML = info.device.join(" / ");
        if(info.core[0]==="msie"&&/*@cc_on!@*/0){
            _d("browserMode").innerHTML = info.browserMode;
            _d("documentMode").innerHTML = info.documentMode;
        }
    })();
  • 相关阅读:
    Android Studio更新升级方法
    手把手教你用android studio创建第一个安卓程序加载html5页面(二)
    手把手教你用android studio创建第一个安卓程序加载html5页面(一)
    spoon kettle连接数据库失败解决方法
    AE多用户同时编辑同一个版本数据的解决方法
    ARCGIS知乎上的好文章
    mac系统访问windows共享文件夹
    奶爸程序员的“育儿”心得
    tomcat取带有中文的参数乱码的解决办法
    java问题排查可能用到的一些命令
  • 原文地址:https://www.cnblogs.com/jiemao/p/2708135.html
Copyright © 2011-2022 走看看