通过js中的useragrent来判断设备是pc端还是移动端,跳转不同的地址

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|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
                //手机 
                window.location.href="http://www.mobile.com"; 
            }else if(/iPad/i.test(navigator.userAgent)){ 
                //ipad
                window.location.href="http://ipad.com" 
            }else{ 
                //电脑
                window.location.href="http://pc.com" 
            } 
        }catch(e){} 
    } 
} 
原文地址:https://www.cnblogs.com/LChenglong/p/7502707.html