Home > Web Front-end > JS Tutorial > body text

Jumping between PC and mobile phone based on JavaScript code_javascript skills

WBOY
Release: 2016-05-16 15:24:08
Original
922 people have browsed it

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>
Copy after login

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>
Copy after login

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";
    }
 }
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template