首页 > 学习笔记 > JavaScript > 正文

判断访问的是移动端还是PC端,如果是移动端跳转移动端页面

发布时间:2017-03-20 09:53:52 点击量:

<script type="text/javascript">
        var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");

        var browser = navigator.userAgent.toLowerCase();

        var isMobile = false;

        for (var i = 0; i < mobileAgent.length; i++) {
            if (browser.indexOf(mobileAgent[i]) != -1) {
                isMobile = true;

                //alert(mobileAgent[i]);

                location.href = '要跳转的网址';

                break;
            }
        }
    </script>

上一篇:js点击获取验证码倒计时效果

下一篇:js 随机获取10个不重复的1~100之间的整数数组