js判断是pc端还是移动端(window.navigator.userAgent)

js判断是pc端还是移动端(window.navigator.userAgent),第1张

判断移动端还是电脑端 代码查看navigator

代码
    <script>
        //定义一个函数判断是手机端还是pc端
        function isMobile(){
            if(window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
              return true; // 移动端
            }else{
              return false; // PC端
            }
        }
        //    判断后的 *** 作
        if(isMobile()){
            location.href="./mobile/index.html"//移动端的页面
            // 判断true跳转到这个主页
        }else{
            location.href="./pc/index.html"//电脑端的页面
            // 判断false跳转到这个主页
        }
    </script>  
查看navigator

部分转载自 js判断是pc端还是移动端(window.navigator.userAgent).

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/996596.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存