电脑PC端跳转到手机端的js判断代码

时间:2017-09-09
第一种方法:
 
<script type="text/javascript">
function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["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;
}
var currentUrl = window.location.href;
if(!IsPC())
{
//手机端对应的网页跳转
document.location.href = "http://m.genban.org";
}
</script>
 
第二种方法:
 
 
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="http://m.genban.org";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
 
上一条:PHP超时提示Fatal error: Maximum execution time of 30,解决方案 下一条:微信网页扫码登录与微信公众号授权登录的区别

相关文章

最新文章