当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 使用js判断用户是pc端还是手机端

使用js判断用户是pc端还是手机端

2020年07月08日  | 移动技术网IT编程  | 我要评论
<script type="text/javascript">
            function browserRedirect() {
                var sUserAgent = navigator.userAgent.toLowerCase();
                if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(sUserAgent)) {
                    //跳转移动端页面
                    window.location.href="${ctxMJiangxin}/";
                } else {
                    //跳转pc端页面
                    window.location.href="${ctxJiangxin}/";
                }
            }
            browserRedirect();
        </script>
<script type="text/javascript">
try {
           if ((navigator.userAgent.match(/(iphone|ipod|android|ios|windows phone)/i))) {
               //跳转移动端页面
               window.location.href="${ctxMJiangxin}/";
           }else{
           }
       } catch (e) {
       }
</script>

本文地址:https://blog.csdn.net/weixin_43968374/article/details/107174783

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网