判断移动端还是电脑端跳转到不同文件

做了一个pc端一个移动端的网站,然后他们说要一个入口文件,根据不同设备大小打开不同文件,于是就有了下面这段:

<script type="text/javascript">
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="phone.html";
}else if(/iPad/i.test(navigator.userAgent)){
}else{
window.location.href="phone.html"
}
}catch(e){}
}
}else{
window.location.href="pc.html"
}
</script>

 

 

 

posted @ 2018-07-20 13:51  jamiezou  阅读(122)  评论(0编辑  收藏  举报