网页识别手机的javascript脚本
现在的网站基本上都是pc网页+移动wap版的标配了。在手机访问网页的pc版时如何让网页自动跳转到相应的移动版?以下js脚本可以使用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<script> function IsMobile() { var userAgentInfo = navigator.userAgent.toLowerCase(); var mobileAgents = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire","windows phone","symbianos"); var isMobile = false; for (var v = 0; v < mobileAgents.length; v++) { if (userAgentInfo.indexOf(mobileAgents[v]) > 0) { isMobile = true; break; } } return isMobile; } if(IsMobile()){ //location.href= "/mobile/"; //location.href = 'http://m.xxxxx.com'+location.pathname; //location.href = 'http://m.xxxxx.com'+location.pathname + location.search;//路径待参数的 } </script> |