js判断是手机访问还是电脑访问

var url = patt1.exec(location.href);
        if (navigator.userAgent.toLowerCase().indexOf("micromessenger") > -1) {
            window.location.href = "http://www.360doc26.net/wxarticlenew/" + url.toString().split("_")[1] + ".html";
                        
        }
        else if (navigator.userAgent.indexOf("iPhone") > 0 || navigator.userAgent.indexOf("Android") > 0 || navigator.userAgent.indexOf("iPod") > 0) {  //手机端跳转

            if (url != "") {
                self.location = "http://www.360doc.cn/article/" + url + ".html";
            }
        }
原文地址:https://www.cnblogs.com/netlock/p/13194620.html