JS判断手机访问网站然后进行重定向的代码

在需要跳转的PC网站的网页<head>区域上加入如下代码,如果是移动端访问的话,就跳转到相应的移动端网页。

<script type="text/javascript">
     try {
         var urlhash = window.location.hash;
         if (!urlhash.match("fromapp")) {
             if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {
                 window.location = "http://m.59178.com/";
             }
         }
     } 
     catch (err) {
     }
 </script>

猜你喜欢

转载自blog.csdn.net/qhdzj87/article/details/82345743