js判断浏览器类型

通过 navigator.userAgent 属性可以判断用户是用的什么浏览器。
PC:window 、苹果……
移动端:安卓 、苹果……

if (window.location.toString().indexOf('pref=padindex') != -1) {
    } else {
        if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || /\(Android.*Mobile.+\).+Gecko.+Firefox/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))) {
            if (window.location.href.indexOf("?mobile")<0){
                try {
                    if (/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
                        window.location.href="https://xw.qq.com?f=qqcom";
                    } else if (/iPad/i.test(navigator.userAgent)) {
                        //window.location.href="http://www.qq.com/pad/"
                    } else {
                        window.location.href="http://xw.qq.com/simple/s/index/"
                    }
                } catch (e) {}
            }
        }
    }

你可能感兴趣的:(js判断浏览器类型)