zoukankan      html  css  js  c++  java
  • 手机端自动跳转

      方法1:

    <SCRIPT LANGUAGE="JavaScript">
     function mobile_device_detect(url)
     {
            var thisOS=navigator.platform;
            var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
     for(var i=0;i<os.length;i++)
            {
     if(thisOS.match(os[i]))
            {  
      window.location=url;
     }
              
     }
     //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
     if(navigator.platform.indexOf('iPad') != -1)
            {
      window.location=url;
     }
     //做这一部分是因为Android手机的内核也是Linux
     //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
      var check = navigator.appVersion;
      if( check.match(/linux/i) )
              {
       //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
       if(check.match(/mobile/i) || check.match(/X11/i))
                     {
       window.location=url;
       } 
     }
     //类in_array函数
     Array.prototype.in_array = function(e)
     {
      for(i=0;i<this.length;i++)
      {
       if(this[i] == e)
       return true;
      }
      return false;
     }
     }
    mobile_device_detect("http://m.16css.com");
    </SCRIPT>
    

      方法2:

    <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.16css.com/";
    }
    }
    }
    catch(err)
    {
    }
    </script>
    

      方法3:

    <script type="text/javascript">
    // JavaScript Document
    function urlredirect() {
        var sUserAgent = navigator.userAgent.toLowerCase(); 
        if ((sUserAgent.match(/(ipod|iphone os|midp|ucweb|android|windows ce|windows mobile)/i))) {
            // PC跳转移动端
            var thisUrl = window.location.href;
            window.location.href = thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'mobile/';
             
        }
    }
    urlredirect();
    </script>
    

      

      58同城:

    <meta name="mobile-agent" content="format=xhtml; url=http://m.58.com/local/xa/">
    <meta name="mobile-agent" content="format=html5; url=http://m.58.com/local/xa/">
    <meta name="mobile-agent" content="format=wml; url=http://m.58.com/local/xa/">
    

      腾讯拍拍网:

    <script type="text/javascript">
      if (/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        var url = "http://2.paipai.com/h5/item/nearby.shtml";
        window.location.href = url;
      }
    </script>
    

       京东: 

    var ua  = w.navigator.userAgent.toLocaleLowerCase();
    var matchedRE = /iphone|android|symbianos|windowssphone/g;
    if ( matchedRE.test(ua)) {
            w.location.href = url;
       } 
    

       大秦网:

    <script> 
      function browserRedirect() {
          var sUserAgent = navigator.userAgent.toLowerCase();
          var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
          var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
          var bIsMidp = sUserAgent.match(/midp/i) == "midp";
          var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
          var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
          var bIsAndroid = sUserAgent.match(/android/i) == "android";
          var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
          var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
          if((bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsCE || bIsWM) && window.location.href.indexOf("?mobile") < 0){
                window.location.href="http://xw.qq.com/iphone/m/shanxi/index.htm#TencentIndex";
          }
      }
      browserRedirect();
    </script>
    

      腾讯网:

    <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|SonyEri    csson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){  
          if(window.location.href.indexOf("?mobile")<0){
    		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)){
                  	         window.location.href="http://www.qq.com/pad/"
    			}else{
    				window.location.href="http://xw.qq.com/simple/s/index/"
    		     }
    		}catch(e){}
         }
      }
    
    </script>
    

      

  • 相关阅读:
    安装 Office Online Server2016
    HTML-冒泡算法
    shell 中的$0 $1 $* $@ $# $$ $? $() $(())
    线程池原理及C语言实现线程池
    彻底搞懂Reactor模型和Proactor模型
    TCP的三次握手与四次挥手理解及面试题
    socket关闭的close和shutdown区别
    C++ Virtual 完美诠释
    Linux学习之CentOS--Linux系统的网络环境配置
    Linux学习之CentOS--Linux网卡高级命令、IP别名及多网卡绑定
  • 原文地址:https://www.cnblogs.com/onesmail/p/5381647.html
Copyright © 2011-2022 走看看