"JavaScript" through JavaScript, if the phone browser access to the PC version of the page, automatically jump to the mobile version of the page

Source: Internet
Author: User

This actually does not have to write their own, because there is a very good writing on the Internet JS.

To achieve the following effect, if the PC, tablet access to this page, then display the PC version of the page, if the mobile phone access to this page will jump to the mobile version of the page, while not loading the PC version of the page, jump directly.


First, the directory structure is as follows:


The JS folder in which the uaredirect.js is down from the Internet, its code is as follows:

function Uaredirect (f) {try{if (document.getElementById ("Bdmark")!=null) {Return}var b=false;if (arguments[1]) {var e= Window.location.host;var a=window.location.href;if (Issubdomain (arguments[1],e) ==1) {f=f+ "/#m/" +a;b=true}else{if ( Issubdomain (arguments[1],e) ==2) {f=f+ "/#m/" +a;b=true}else{f=a;b=false}}}else{b=true}if (b) {var c= Window.location.hash;if (!c.match ("Fromapp")) {if (Navigator.userAgent.match (/(iphone|ipod| Android|ios)) {location.replace (f)}}}}catch (d) {}}function Issubdomain (c,d) {this.getdomain=function (f) {var e= F.indexof ("://"), if (e>0) {var h=f.substr (e+3)}else{var H=f}var g=/^www\./;if (g.test (h)) {H=h.substr (4)}return H}; if (C==d) {return 1}else{var c=this.getdomain (c); var b=this.getdomain (d); if (c==b) {return 1}else{c=c.replace (".", "\ \."); var a=new RegExp ("\ \.") +c+ "$"); if (B.match (a)) {return 2}else{return 0}}};
You can directly copy to use it, and then the PC version of the page header, add the following things:

<script src= "Js/uaredirect.js" type= "Text/javascript" ></script><script>uaredirect ("ml.html"); </script>
This will see the effect.

The above pc.html full code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The ml.html code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
There's nothing special about HTML pages that are simply no longer easy.

"JavaScript" through JavaScript, if the phone browser access to the PC version of the page, automatically jump to the mobile version of the page

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.