识别移动端网页的javascript脚本

现在的网站基本上都是pc网页+移动wap版的标配了。在手机访问网页的pc版时如何让网页自动跳转到相应的移动版?以下js脚本可以使用:

<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>

相关文章:

原文来自:http://www.oicto.com/javascript-is-mobile/