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

分享兩個(gè)手機(jī)訪問pc網(wǎng)站自動(dòng)跳轉(zhuǎn)手機(jī)端網(wǎng)站代碼

 更新時(shí)間:2020年12月24日 21:00:01   投稿:mdxy-dxy  
這篇文章主要介紹了分享兩個(gè)手機(jī)訪問pc網(wǎng)站自動(dòng)跳轉(zhuǎn)手機(jī)端網(wǎng)站代碼,需要的朋友可以參考下

4G降臨,移動(dòng)網(wǎng)站已經(jīng)一發(fā)不可收拾,pc端和移動(dòng)端官網(wǎng)并存。如何讓別人訪問你的pc端的官網(wǎng)直接跳轉(zhuǎn)到移動(dòng)端的網(wǎng)站呢?各位看官,小二上代碼!來(lái)了!

常用的訪問pc自動(dòng)跳轉(zhuǎn)到移動(dòng)頁(yè)面的代碼

(function() {
      if (/Android|webOS|iPhone|iPad|Windows Phone|iPod|BlackBerry|SymbianOS|Nokia|Mobile|Opera Mini/i.test(navigator.userAgent)) {
        var siteName = window.location.pathname;
        if (url.indexOf("?pc") < 0) {
          try {
				if (typeof siteName !== "undefined") {
            	window.location. + siteName
          		} 
          } catch (e) {}
        }
      }
    })();

訪問移動(dòng)端自動(dòng)跳pc端的代碼

;(function() {
  var reWriteUrl = function(url) {
    if (url) {
      var Splits = url.split("/"),
      siteName = window.location.pathname;
      if (typeof siteName !== "undefined") {
        return "http://www.dbjr.com.cn" + siteName
      }
    }
  };
  if (!/Android|webOS|iPhone|iPad|Windows Phone|iPod|BlackBerry|SymbianOS|Nokia|Mobile|Opera Mini/i.test(navigator.userAgent)) {
    var url = window.location.href;
    var pathname = window.location.pathname;
    if (url.indexOf("?m") < 0) {
      try {
        window.location.href = reWriteUrl(url)
      } catch(e) {}
    }
  }
})();

判斷瀏覽器是否為手機(jī)端

<script type="text/javascript">
(function(){var reWriteUrl=function(url){if(url){var Splits=url.split("/"),siteName=window.location.pathname;if(typeof siteName!=="undefined"){return"https://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("?pc")<0){try{window.location.href=reWriteUrl(url)}catch(e){}}}})();
</script>

判斷瀏覽器是否為pc端,是就跳到pc頁(yè)面

<script>
var browser1 = {
	 versions: function () {
	  var u = navigator.userAgent, app = navigator.appVersion;
	  return {//移動(dòng)終端瀏覽器版本信息
	   trident: u.indexOf('Trident') > -1, //IE內(nèi)核
	   presto: u.indexOf('Presto') > -1, //opera內(nèi)核
	   webKit: u.indexOf('AppleWebKit') > -1, //蘋果、谷歌內(nèi)核
	   gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐內(nèi)核
	   mobile: !!u.match(/AppleWebKit.*Mobile/i) || !!u.match(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/), //是否為移動(dòng)終端
	   ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios終端
	   android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android終端或者uc瀏覽器
	   iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否為iPhone或者QQHD瀏覽器
	   iPad: u.indexOf('iPad') > -1, //是否iPad
	   webApp: u.indexOf('Safari') == -1 //是否web應(yīng)該程序,沒有頭部與底部
	  };
	 } (),
	 language: (navigator.browserLanguage || navigator.language).toLowerCase()
	}

if(browser1.versions.mobile==false&&browser1.versions.ios==false&&browser1.versions.android==false&&browser1.versions.iPhone==false &&browser1.versions.iPad==false){
		//location.href = location.href.replace("m.","www.");//如果不是手機(jī)打開,則跳轉(zhuǎn)到pc頁(yè)面
		alert("pc");
	}

</script>

以下是補(bǔ)充可以參考

jQuery判斷瀏覽器是移動(dòng)端還是電腦端自動(dòng)跳轉(zhuǎn)

一個(gè)段小代碼,同一個(gè)網(wǎng)站針對(duì)移動(dòng)端查看和電腦端查看跳轉(zhuǎn)不同的頁(yè)面。
首先加載jQuery文件。

$(function(){ 
 var MobileUA = (function() { 
  var ua = navigator.userAgent.toLowerCase(); 
 
  var mua = { 
   IOS: /ipod|iphone|ipad/.test(ua), //iOS 
   IPHONE: /iphone/.test(ua), //iPhone 
   IPAD: /ipad/.test(ua), //iPad 
   ANDROID: /android/.test(ua), //Android Device 
   WINDOWS: /windows/.test(ua), //Windows Device 
   TOUCH_DEVICE: ('ontouchstart' in window) || /touch/.test(ua), //Touch Device 
   MOBILE: /mobile/.test(ua), //Mobile Device (iPad) 
   ANDROID_TABLET: false, //Android Tablet 
   WINDOWS_TABLET: false, //Windows Tablet 
   TABLET: false, //Tablet (iPad, Android, Windows) 
   SMART_PHONE: false //Smart Phone (iPhone, Android) 
  }; 
 
  mua.ANDROID_TABLET = mua.ANDROID && !mua.MOBILE; 
  mua.WINDOWS_TABLET = mua.WINDOWS && /tablet/.test(ua); 
  mua.TABLET = mua.IPAD || mua.ANDROID_TABLET || mua.WINDOWS_TABLET; 
  mua.SMART_PHONE = mua.MOBILE && !mua.TABLET; 
 
  return mua; 
 }()); 
 
 //SmartPhone 
 if (MobileUA.SMART_PHONE) { 
  // 移動(dòng)端鏈接地址 
   
  document.location.; 
 } 
}); 

 需要手機(jī)端也網(wǎng)頁(yè)的數(shù)據(jù)同步

復(fù)制代碼 代碼如下:

<script type="text/javascript">
(function(){var ua=navigator.userAgent.toLowerCase();var bIsIpad=ua.match(/ipad/i)=="ipad";var bIsIphoneOs=ua.match(/iphone os/i)=="iphone os";var bIsAndroid=ua.match(/android/i)=="android";var bIsWM=ua.match(/windows mobile/i)=="windows mobile";if(bIsIpad||bIsIphoneOs||bIsAndroid||bIsWM){window.location.}})();
</script>

第二種方法:

 <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;
 } 
 }
 
 //因?yàn)橄喈?dāng)部分的手機(jī)系統(tǒng)不知道信息,這里是做臨時(shí)性特殊辨認(rèn)
 if(navigator.platform.indexOf('iPad') != -1)
 {
 window.location=url;
 }
 
 //做這一部分是因?yàn)锳ndroid手機(jī)的內(nèi)核也是Linux
 //但是navigator.platform顯示信息不盡相同情況繁多,因此從瀏覽器下手,即用navigator.appVersion信息做判斷
 var check = navigator.appVersion;
 
 if( check.match(/linux/i) )
  {
 //X11是UC瀏覽器的平臺(tái) ,如果有其他特殊瀏覽器也可以附加上條件
 if(check.match(/mobile/i) || check.match(/X11/i))
   {
 window.location=url;
 } 
 }
 
 //類in_array函數(shù)
 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://***.***.com");
</SCRIPT>

備注這里的
mobile_device_detect("http://***.***.com");//里面的地址填的就是您的移動(dòng)端的網(wǎng)站地址呦。

相關(guān)文章

最新評(píng)論