js判断是否手机访问
<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))){ 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)){ }else{ window.location.href="http://xw.qq.com/simple/s/index/" } }catch(e){} } </script>
AppleWebKit.*Mobile 说明:
点 是任意字符
* 是取 0 至 无限长度
.* 就是匹配AppleWebKit xxxxxxxxxxxx(任意字符) Mobile
手机浏览器User-Agent信息
3个例子如下:
2345浏览器
Mozilla/5.0 (Linux; U; Android 4.2.2; zh-cn; Galaxy Nexus Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/5.0 Mb2345Browser/4.0 Mobile Safari/534.30
遨游浏览器
Mozilla/5.0 (Linux; U; Android 4.2.1; zh-cn; AMOI N828 Build/JOP40D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 Maxthon
UC浏览器
Mozilla/5.0 (Linux; U; Android 4.2.1; zh-CN; AMOI N828 Build/JOP40D) AppleWebKit/534.31 (KHTML, like Gecko) UCBrowser/9.2.4.329 U3/0.8.0 Mobile Safari/534.31