判斷是手機端仍是PC短訪問

第一種:判斷是手機訪問仍是PC訪問

<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 (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
      //跳轉到PC端地址
      window.location.href='http://www.jd.com';
    }else{
      //跳轉到移動端地址
      window.location.href='http://m.jd.com';
    }
  }javascript

  browserRedirect();
</script>css

 

第二種:判斷是手機訪問仍是PC訪問java


var system ={};
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){//若是是電腦跳轉到百度
  window.location.href="http://www.baidu.com/";
}else{ //若是是手機,跳轉到谷歌
  window.location.href="http://www.google.cn/";
}android

 

第三種:判斷是手機訪問仍是PC訪問web


<script>windows

if(navigator.platform.indexOf('Win32')!=-1){
  //pc
  //window.location.href="電腦網址";
}else{
  //手機
  window.location.href="手機網址";
}
</script>瀏覽器


第四種:百度判斷是手機仍是PC訪 問app


<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js"type="text/javascript"></script>
<script type="text/javascript">uaredirect("http://m.XXX.com")//手機網址;</script>webapp

將代碼網址部分改爲你網站的手機網址就Ok,固然能夠是任意網址!iphone

 

第五種:判斷是手機仍是PC跳轉到指定的地址*

下面這段代碼是判斷瀏覽器是手機瀏覽器,而後自動跳轉到mobile.com,怎麼修改,才能
把不是用手機瀏覽器的人,在上mobile.com的時候,自動跳轉到PC.COM

<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| SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){   if(window.location.href.indexOf("?mobile")<0){     try{       if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){         //手機         window.location.href="http://www.mobile.com";       }else if(/iPad/i.test(navigator.userAgent)){         //ipad         window.location.href="http://ipad.com"       }else{         //電腦         window.location.href="http://pc.com"       }     }catch(e){}   } } </script>

相關文章
相關標籤/搜索