javascript - 非手机浏览器上Mobile网站时如何自动跳转到PC端?
本文介绍了javascript - 非手机浏览器上Mobile网站时如何自动跳转到PC端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
下面这段代码是判断浏览器是手机浏览器,然后自动跳转到mobile.com,请问怎么修改,才能把不是用手机浏览器的人,在上mobile.com的时候,自动跳转到PC.COM,谢谢。
<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="http://www.mobile.com";
}else if(/iPad/i.test(navigator.userAgent)){
}else{
window.location.href="http://www.mobile.com"
}
}catch(e){}
}
}
</script>
解决方案
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){}
}
}
这篇关于javascript - 非手机浏览器上Mobile网站时如何自动跳转到PC端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文