js判断是手机还是PC端

<script>
        var isMobile = {
            Android: function () {
                return navigator.userAgent.match(/Android/i) ? true : false;
            },
            BlackBerry: function () {
                return navigator.userAgent.match(/BlackBerry/i) ? true : false;
            },
            iOS: function () {
                return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
            },
            Windows: function () {
                return navigator.userAgent.match(/IEMobile/i) ? true : false;
            },
            any: function () {
                return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
            }
        };
        if (isMobile.any()) { //判断是否为android,BlackBerry,ios,windows
            //要执行的代码 跳转到手机端
            window.location.href="/wap/";
        }
</script>

猜你喜欢

转载自blog.csdn.net/weixin_38615720/article/details/87366565