通過js中的useragrent來判斷設備是pc端還是移動端,跳轉不同的地址
阿新 • • 發佈:2017-09-11
lenovo err agent indexof pad ren phi mobile 手機
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端還是移動端,跳轉不同的地址