English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

javascript Judgment of Page Access Method Computer or Mobile End

Method one:

<script type="text/javascript">
function browserRedirect(type) {

/ipad/i) == "ipad";
/iphone os/i) == "iphone os";
/midp/i) == "midp";
var bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:";1.2.3.4";
/ucweb/i) == "ucweb";
/android/i) == "android";
/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= '/ctcshop/m/rhylogin.shtml';
//alert("This is a mobile phone");
} else {
window.location= '/etrade/login.shtml?ref_url=/rhy/index.html';
//alert("This is a computer");
}
}
</script>
 //method1:
function IsPC() {
 var userAgentInfo = navigator.userAgent;
 var Agents = ["Android", "iPhone",
 "SymbianOS", "Windows Phone",
 "iPad", "iPod"]
 var flag = true;
 for (var v = 0; v < Agents.length; v++) {
 if (userAgentInfo.indexOf(Agents[v]) > 0) {
 flag = false;
 break;
 }
 }
 return flag;
}

method2:

function browserRedirect() {
 
 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='B page';
 }
}
browserRedirect();

method3:

<script type="text/javascript">
 var browser = {
 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 kernels  
 gecko : u.indexOf('Gecko') > -1 && u.indexOf('KHTML') === -1, //Firefox kernel  
 mobile : !!u.match(/AppleWebKit.*Mobile.*/)}}
  || !!u.match(/AppleWebKit/, //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 it a web application, without header and footer
 google:u.indexOf('Chrome')>-1
 ;
 }
 language : (navigator.browserLanguage || navigator.language).toLowerCase()
 }
 document.writeln("Language version: ")+browser.language);
 document.writeln("Is it a mobile terminal: ")+browser.versions.mobile);
</script>

This is the summary of the materials for judging the access method of the page. We will continue to supplement relevant materials in the future, thank you for your support to this site!

Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email for reporting, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)

You May Also Like