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