Simple method: Through the Baidu site app to judge:
Embed the following code in the header of the Web page:
<script src= "Http://siteapp.baidu.com/static/webappservice/uaredirect.js" type= "Text/javascript" ></ Script><script type= "Text/javascript" >uaredirect ("http://m.baidu.com");//Please change the URL of your mobile station to the URL of the website </script >
Here is attached uaredirect.js file source code, for yourself to learn:
functionUaredirect (f) {Try { if(document.getElementById ("Bdmark")! =NULL) { return } varb =false; if(arguments[1]) { varE =Window.location.host; varA =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) {varc =Window.location.hash; if(!c.match ("Fromapp")) { if((Navigator.userAgent.match (/(iphone|ipod| Android|ios)/i)) {Location.replace (f)} }}}Catch(d) {}}functionIssubdomain (c, D) { This. GetDomain =function(f) {varE = F.indexof ("://"); if(E > 0) { varH = f.substr (e + 3) } Else { varh =F}varg =/^www\./; if(G.test (h)) {h= H.substr (4) } returnh}; if(c = =d) {return1 } Else { varc = This. GetDomain (c); varb = This. GetDomain (d); if(c = =b) {return1 } Else{C= C.replace (".", "\ \.")); varA =NewREGEXP ("\ \" + C + "$")); if(B.match (a)) {return2 } Else { return0 } } }};
Judge Mobile WAP website Jump source