The technique of jumping _javascript between PC and mobile phone based on JavaScript code

Source: Internet
Author: User

This code is placed inside the code of the PC template.

<script type= "Text/javascript" > 
//platforms, devices and operating systems 
var system ={Win:false, Mac:false 
, XLL 
: False 
}; 
Detection Platform 
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= "Mobile url";
}
</script>

This code is in the mobile website template

<script type= "Text/javascript" > 
//platforms, devices and operating systems 
var system ={ 
Win:false, 
mac:false, 
Xll:false 
};
Detection Platform
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 URL";
} else{ 
}
</script>

Ps:js to judge the mobile end and PC-side jump code

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 a small series to introduce the JavaScript code based on the realization of the PC and mobile phone jump between the whole narrative, I hope you like.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.