JavaScript判断是否是手机端浏览还是电脑…

2,136 阅读1分钟
 function IsPC() {
            var userAgentInfo = navigator.userAgent;
            console.log(navigator.userAgent);
            var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
            var flag = true;
            for (var v = 0; v < Agents.length; v++) {
                if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
            }
            return flag;
        }

        if (IsPC()) {
            console.log("isPc");
            window.location = "http://www.hjclass.com/classzt/MKTTopic_474"+location.search;
        } else {
            console.log("isMobile");
        }