With the arrival of 4G, mobile websites are out of control, and the PC and mobile official websites coexist. How to get others to visit your PC official website and jump directly to the mobile website? Dear readers, please add the code! Here comes!
Determine whether the browser is a mobile phone
<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.VeVB.COM"+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>To determine whether the browser is a PC, jump to the PC page
<script>var browser1 = { versions: function () { var u = navigator.userAgent, app = navigator.appVersion; return {//Mobile terminal browser version information trident: u.indexOf('Trident') > -1, //IE kernel presto: u.indexOf('Presto') > -1, //opera kernel webKit: u.indexOf('AppleWebKit') > -1, //Apple and Google kernel gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //Firefox kernel 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/), //Is it a mobile terminal ios: !!u.match(//(i[^;]+;( U;)? CPU.+Mac OS X/), //ios terminal android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //Android terminal or uc browser iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //Is it an iPhone or QQHD browser iPad: u.indexOf('iPad') > -1, //Is it an iPad webApp: u.indexOf('Safari') == -1 //Is the web supposed to program, no header and bottom}; } (), 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.");//If it is not the phone open, jump to the pc page alert("pc");}</script>The following are supplements for reference
jQuery determines whether the browser is a mobile or computer-based browser automatically jumps
A small code, the same website jumps to different pages for mobile and computer viewing.
First load the jQuery file.
$(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) { // Mobile link address document.location.href = 'http://www.aaa.com/wap/index.html'; } });The data synchronization of the web pages is required on the mobile phone
The code copy is as follows:
<script type="text/javascript">
(function(){var ua=navigator.userAgent.toLowerCase();var bIsIpad=ua.match(/ipad/i)=="ipad";var bIsIphoneOs=ua.match(/iiphone 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.href="http://m.VeVB.COM/android/game/826.html"}})();
</script>
The second method:
<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; } } //Because a considerable number of mobile phone systems do not know the information, here is a temporary special identification if(navigator.platform.indexOf('iPad') != -1) { window.location=url; } //This part is because the kernel of Android phones is also Linux // However, navigator.platform shows different information, so start with the browser, that is, use navigator.appVersion information to make judgments var check = navigator.appVersion; if( check.match(/linux/i) ) { //X11 is the platform of UC browser. If there are other special browsers, you can also attach the conditions if(check.match(/mobile/i) || check.match(/X11/i)) { window.location=url; } } //Class in_array function 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>Note here
mobile_device_detect("http://***.***.com");//The address inside is filled in to your mobile website address.