獲取瀏覽器類型

 
var browser = {
    versions:function(){
        var u = navigator.userAgent, app = navigator.appVersion;
        return {
            trident: u.indexOf('Trident') > -1,                             //IE內核
            presto: u.indexOf('Presto') > -1,                               //opera內核
            webKit: u.indexOf('AppleWebKit') > -1,                          //蘋果、谷歌內核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,     //火狐內核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/),                     //是否爲移動終端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),                //ios終端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,  //android終端或uc瀏覽器
            iPhone: u.indexOf('iPhone') > -1,                               //是否爲iPhone或者QQHD瀏覽器
            iPad: u.indexOf('iPad') > -1,                                   //是否iPad
            webApp: u.indexOf('Safari') == -1,                              //是否web應該程序,沒有頭部與底部
            weixin: u.indexOf('MicroMessenger') > -1,                       //是否微信
            qq: u.match(/\sQQ/i) == "qq"                                    //是否QQ
        };
    }(),
};
相關文章
相關標籤/搜索