Home >Web Front-end >JS Tutorial >Jumping between PC and mobile phone based on JavaScript code_javascript skills

Jumping between PC and mobile phone based on JavaScript code_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:24:08944browse

This code is placed in the code of the PC template

<script type="text/javascript"> 
//平台、设备和操作系统 
var system ={ 
win : false, 
mac : false, 
xll : false 
}; 
//检测平台 
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){   
}else{
window.location.href="手机网址";
}
</script>

This code is placed in the mobile website template

<script type="text/javascript"> 
//平台、设备和操作系统 
var system ={ 
win : false, 
mac : false, 
xll : false 
};
//检测平台
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="PC网址";
}else{ 
}
</script>

PS: JS determines the mobile and PC jump codes

var browser_class = navigator.userAgent;
 var browser_class_name1 = browser_class.match("Mobile");
 var browser_class_name2 = browser_class.match("mobile");
 var location_url = window.location.href;
 if (browser_class_name1 != null || browser_class_name2 != null){
     if (location_url.match("wap") == null){
     window.location.href="http://wap.xxxx.com";
     }
 } else
 {
    if (location_url.match("3g") != null || location_url.match("wap") != null){
    window.location.href="http://wap.xxxx.com";
    }
 }

The above content is the entire description of the jump between PC and mobile phone based on JavaScript code introduced by the editor. I hope you like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn