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

Posted AiTing on the way

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过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){} 
    } 
} 

 

以上是关于通过js中的useragrent来判断设备是pc端还是移动端,跳转不同的地址的主要内容,如果未能解决你的问题,请参考以下文章