您的位置:首页 > 移动开发

js判断访问端为pc端或者移动端,并跳转到对应版面

2016-10-24 15:34 513 查看
<script>

    var pc_style = ""

    var browser = {

        versions: function () {

            var u = navigator.userAgent, app = navigator.appVersion;

            return {

                trident: u.indexOf('Trident') > -1,

                presto: u.indexOf('Presto') > -1,

                webKit: u.indexOf('AppleWebKit') > -1,

                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,

                mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/) && u.indexOf('QIHU') && u.indexOf('QIHU') > -1 && u.indexOf('Chrome') < 0,

                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),

                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,

                iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1,

                iPad: u.indexOf('iPad') > -1,

                webApp: u.indexOf('Safari') == -1,

                ua: u

            };

        }(),

        language: (navigator.browserLanguage || navigator.language).toLowerCase()

    }

    if (browser.versions.mobile && !browser.versions.iPad) {

        this.location = "./wap/";

    }

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  js 移动端 pc端