JavaScript

PC跳转Mobile端JS代码

LensNews

 

方法一:

<!--手机端访问调转 start-->
    <script type="text/javascript">
          function mobile_device_detect()
          {
            var url = location.protocol + '//m.darryring.com' + location.pathname+location.search;
              var thisOS=navigator.platform + navigator.userAgent;
       
              var os=new Array("iPhone","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv7l","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
              for(var i=0;i<os.length;i++)
              {
                  if(thisOS.match(os[i]))
                  {
                      window.location=url;
                  }

              }
              var check = navigator.appVersion;

              if( check.match(/linux/i) )
              {
                  if(check.match(/mobile/i) || check.match(/X11/i))
                  {
                      window.location=url;
                  }
              }

              Array.prototype.in_array = function(e)
              {
                  for(i=0;i<this.length;i++)
                  {
                      if(this[i] == e)
                          return true;
                  }
                  return false;
              }
          }
          mobile_device_detect(); 
      </script>

方法二

<script>
    var originHref = window.location.href;
    var afterSchema = originHref.indexOf("://") + 3;
    var domainEnd = originHref.indexOf("/", afterSchema);
    var domain = originHref.substring(afterSchema, domainEnd);
    if (domain !== 'm.ido-love.com') {
        if (navigator) {
            var ua = navigator.userAgent.toLowerCase();
            if (/mobile|android|iphone|ipad|phone/i.test(ua)) {
                window.location.href = originHref.substring(0, afterSchema) + 'm.ido-love.com' + originHref.substring(domainEnd);
            }
        }
    }
</script>

 

 

(0)

本文由 SilenceLee的学习笔记 作者:silencelee 发表,转载请注明来源!

LensNews

热评文章

发表回复