移动端访问网站自动跳转到手机版,大家都用的什么方法啊

2015 年 2 月 10 日
 tonghuashuai
环境是 Python Tornado mako

1. 在后端做根据不同设备渲染不同模板

2. 在前端做根据不同设备做跳转

另外前后端判断 PC 和移动设备怎么尽量覆盖更多的浏览器呢
5861 次点击
所在节点    问与答
7 条回复
huage
2015 年 2 月 10 日
<script type="text/javascript">
if(window.location.toString().indexOf('pref=padindex') != -1){
}else{
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|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
window.location.href="http://xw.qq.com/index.htm";
}else if(/iPad/i.test(navigator.userAgent)){
window.location.href="http://www.qq.com/pad/"
}else{
window.location.href="http://xw.qq.com/simple/s/index/"
}
}catch(e){}
}
}
}
</script>

腾讯网
steeeeps
2015 年 2 月 10 日
楼上的改良版,http://steeeeps.net/2015/01/14/get-client-type-by-useragent/
添加了 微信和nexus的判断
mywaiting
2015 年 2 月 10 日
lzsadam
2015 年 2 月 10 日
huage
2015 年 2 月 10 日
@lzsadam 请问你这个应该如何应用到网页中呢?
zenxds
2015 年 2 月 10 日
!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/) || "ontouchstart" in document.documentElement
zenxds
2015 年 2 月 10 日
上面的会包括pad

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/169724

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX