欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js判斷手機(jī)訪問或者PC的幾個(gè)例子(常用于手機(jī)跳轉(zhuǎn))

 更新時(shí)間:2015年12月15日 22:24:45   投稿:mdxy-dxy  
js判斷手機(jī)或者PC的例子我們在幾乎所有網(wǎng)站都會(huì)有這段代碼了,現(xiàn)在手機(jī)流量與pc差不多了,下面來看兩段js判斷手機(jī)或者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) ){
   window.location.href='http://www.dbjr.com.cn';
  }else{
 //window.location.; 
 }
}
$(function(){
 browserRedirect();
});
</script>

例子2

<script type="text/javascript">
(function(){
  var reWriteUrl = function(url){
    if(url){
      var Splits = url.split("/"),siteName=window.location.pathname;
      if(typeof siteName!=="undefined"){
        return "http://m.jb51.net"+siteName;
      }
    }
  };
  if(/Android|webOS|iPhone|iPad|Windows Phone|iPod|BlackBerry|SymbianOS|Nokia|Mobile/i.test(navigator.userAgent)){
    var url=window.location.href;
    var pathname=window.location.pathname;
    if(url.indexOf("?mobile")<0){
    try{
      window.location.href=reWriteUrl(url);
    }catch(e){}
    }
  };
})();
</script>

注意,如果給搜索引擎看的話我們在文件頭加入
<meta http-equiv="mobile-agent" content="format=xhtml; url=http://m.jb51.net" />
<meta http-equiv="mobile-agent" content="format=html5; url=http://m.jb51.net" />
意思是告訴搜索引擎移動(dòng)蜘蛛抓取的是手機(jī)版本的.

相關(guān)文章

最新評論