`
keren
  • 浏览: 1582668 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

通过UserAgent判读客户端的浏览器信息

阅读更多
//Windows NT 6.2 Win8
//Windows NT 6.1 Win7
//Windows XP
//Windows RT Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0)
//(Windows NT 6.1; Trident/7.0; BOIE9;ZHCN; rv:11.0) like Gecko ---IE 11
//"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"
//"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.27.1 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7"
//"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36"
//"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0"
//"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36"
//"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25"
function parser(userAgent) {
    var start = userAgent.indexOf("(");
    userAgent = userAgent.substring(start,userAgent.length);
    var os = "Windows";
    var bit = "32位";
    var brower = "";
    if(userAgent.indexOf("Windows NT 6.2")!=-1){
        os = "Win8";
        if(userAgent.indexOf("ARM;")!=-1){
            os = "WinRT";
        }
    }else if(userAgent.indexOf("Windows NT 6.1")!=-1){
        os = "Win7";
    }else if(userAgent.indexOf("Windows XP")!=-1){
        os = "WinXP";
    }else if(userAgent.indexOf("Linux")!=-1){
        os = "Linux";
    }else if(userAgent.indexOf("Mac")!=-1){
        os = "Mac";
    }
    if(userAgent.indexOf("WOW64")!=-1||userAgent.indexOf("_64")!=-1||userAgent.indexOf("X64")!=-1||userAgent.indexOf("x64")!=-1){
        bit = "64位";
    }

    if(userAgent.indexOf("MSIE")!=-1){
        brower = "IE";
        var start = userAgent.indexOf("MSIE");
        var end = userAgent.indexOf(";",start);
        brower = brower+ userAgent.substring(start+5,end);
    }else if(userAgent.indexOf("rv:")!=-1){
        brower = "IE";
        var start = userAgent.indexOf("rv:");
        var end = userAgent.indexOf(")",start);
        brower = brower+ userAgent.substring(start+3,end);
    }else if(userAgent.indexOf("Firefox")!=-1){
        brower = "Firefox";
        var start = userAgent.indexOf("Firefox/");
        brower = brower + userAgent.substring(start+"Firefox".length+1,userAgent.length);
    }else if(userAgent.indexOf("Chrome")!=-1){
        brower = "Chrome";
        var start = userAgent.indexOf("Chrome/");
        var end = userAgent.indexOf(".",start);
        end = userAgent.indexOf(".",end+1);
        brower = brower + userAgent.substring(start+"Chrome".length+1,end);
    }else if(userAgent.indexOf("Safari")!=-1){
        //Version/5.1.2
        brower = "Safari";
        var start = userAgent.indexOf("Version/");
        var end = userAgent.indexOf(" ",start);
        brower = brower + userAgent.substring(start+"Version".length+1,end);
    }

    return os+"_"+bit+"_"+brower+userAgent;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics