首页 > 建站‧营销

js判断pc端还是移动端代码写法 (js判断终端跳转代码)


方法一:

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="手机页面";
}elseif(/iPad/i.test(navigator.userAgent)){
window.location.href="平板页面";
}else{
window.location.href="其他移动端页a面"
}
}catch(e){}
}
}


方法二:

functiongoPAGE(){
if((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|WindowsPhone)/i))){
/*window.location.href="你的手机版地址";*/
alert("mobile")
}
else{
/*window.location.href="你的电脑版地址";*/
alert("pc")
}
}
goPAGE();


方法三:

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent)){
window.location=你的手机版地址'
}

本文链接:https://www.zhanque.net/cms/4785.html