浏览器判断

判断当前浏览器(包括判断手机客户端种类)

 查询浏览器userAgent方法:地址栏中输入:about:version

function myBrowser(){
        version:function(){
            var u=navigator.userAgent;
            return {
                opera:u.indexOf("Opera")>-1,//opera浏览器
                ie:u.indexOf("compatible")>-1&&u.indexOf("MSIE")>-1&&!isOpera,//IE浏览器
                firfox:u.indexOf("Firefox")>-1,//火狐浏览器
                safari:u.indexOf("Safari")>-1,//safari浏览器
                chrome:u.indexOf("Chrome")>-1,//谷歌浏览器
                ios:!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),//ios终端
                android:u.indexOf("Android")>-1&&u.indexOf("Adr")>-1,//安卓终端
                ipad:u.indexOf("iPad")>-1,//ipad
                weixin:u.indexOf("MicroMessenger")>-1,//微信浏览器
                qq:u.match(/\sQQ/i) == " qq" //QQ浏览器
            }
        }();
     }

  var browser=myBrowser.version;
  if(browser=="ie"){}

var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    if (isIE) {
        var IE5 = IE55 = IE6 = IE7 = IE8 = IE9 =IE10 =IE11 =false;
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        IE55 = fIEVersion == 5.5;
        IE6 = fIEVersion == 6.0;
        IE7 = fIEVersion == 7.0;
        IE8 = fIEVersion == 8.0;
        IE9 = fIEVersion == 9.0;
        IE10 = fIEVersion == 10.0;
        IE11= fIEVersion == 11.0;
        if (IE55) {return "IE55";}
        if (IE6) {return "IE6";}
        if (IE7) {return "IE7";}
        if (IE8) {return "IE8";}
        if (IE9) {return "IE9";}
        if (IE10) {return "IE10";}
        if (IE11) {return "IE11";}
    }//isIE end

 

posted @ 2018-06-13 11:32  奕佚  阅读(217)  评论(1编辑  收藏  举报