检测浏览器的特性

1.检测桌面端浏览器的特性。

$.checkDetect =  function() {
         var Detect = {
            ie: /msie\s*\d+\.\d/gi,
            chrome: /chrome\/[\w\.]+(\s)?/gi,
            firefox: /firefox\/[\w\.]+(\s)?/gi,
        };

         var ua = navigator.userAgent.toLowerCase(),
            info = {},
            match = [];

         for (i  in Detect) {
            match = ua.match(Detect[i]);
             if (match) {
                info.browser = i;
                info.version = match.join(" ").match(/[0-9]+/g).join(".");
            }
        }
         return info;
    }

 检测移动端浏览器属性:

 checkDetect =  function(){
             var Detect = {
                webkit: /(AppleWebKit)[ \/]([\w.]+)/,
                ipad: /(ipad).+\sos\s([\d+\_]+)/i,
                windows: /(windows\d*)\snt\s([\d+\.]+)/i,
                iphone: /(iphone)\sos\s([\d+\_]+)/i,
                ipod: /(ipod).+\sos\s([\d+\_]+)/i,
                android: /(android)\s([\d+\.]+)/i
            };

             var ua = window.navigator.userAgent,
                browser = Detect.webkit.exec(ua),
                ios = /\((iPhone|iPad|iPod)/i.test(ua),
                 // ["iPhone OS 5_1", "iPhone", "5_1"]
                tmp = [],
                N = {},
                match = [];
                 for(i  in Detect){
                    match = Detect[i].exec(ua);
                     if(match){
                        tmp = Detect[i].exec(ua);
                    }  
                }
                N = {
                    system : tmp[1].toLowerCase(),
                    version : tmp[2].replace(/(\_|\.)/ig, '.').toLowerCase(),
                    browser : browser ? browser[1].toLowerCase() : 'apple/webkit',
                    ios: ios
                }
                 return N;
} 

 

        

转载于:https://www.cnblogs.com/heimanba/p/3868863.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值