These are the codes that I found on the internet and are for reference only when I do my own projects:
The first type:
1 functionFbrowserredirect () {2 varSuseragent =navigator.userAgent.toLowerCase ();3 varBisipad = Suseragent.match (/ipad/i) = = "ipad";4 varBisiphoneos = Suseragent.match (/iphone os/i) = = "iphone OS";5 varBISMIDP = Suseragent.match (/midp/i) = = "MIDP";6 varBIsUc7 = Suseragent.match (/rv:1.2.3.4/i) = = "rv:1.2.3.4";7 varBISUC = Suseragent.match (/ucweb/i) = = "UCWeb";8 varBisandroid = Suseragent.match (/android/i) = = "Android";9 varBisce = Suseragent.match (/windows ce/i) = = "Windows CE";Ten varBISWM = Suseragent.match (/windows mobile/i) = = "Windows Mobile"; One A if(bisipad) { -Window.location.href = "http://ipad.tongzhuo100.com/"; -}Else if(Bisiphoneos | | bisandroid | | bismidp | | bIsUc7 | | bisuc | | bisce | |biswm) { theWindow.location.href = "http://wap.tongzhuo100.com/"; - } - Else{ - //alert ("Pc/mac/lunix" +suseragent); + } - } +Fbrowserredirect ();
The second type of Baidu:
1 functionUaredirect (f) {2 Try {3 if(document.getElementById ("Bdmark")! =NULL) {4 return5 }6 varb =false;7 if(arguments[1]) {8 varE =Window.location.host;9 varA =window.location.href;Ten if(Issubdomain (arguments[1], e) = = 1) { Onef = f + "/#m/" +A; Ab =true -}Else { - if(Issubdomain (arguments[1], e) = = 2) { thef = f + "/#m/" +A; -b =true -}Else { -f =A; +b =false - } + } A}Else { atb =true - } - if(b) { - varc =Window.location.hash; - if(!c.match ("Fromapp")) { - if((Navigator.userAgent.match (/(iphone|ipod| android|ios| SymbianOS)/i )) { in Location.replace (f) - } to } + } -}Catch(d) {} the } * functionIssubdomain (c, D) { $ This. GetDomain =function(f) {Panax Notoginseng varE = F.indexof ("://"); - if(E > 0) { the varH = f.substr (e + 3) +}Else { A varh =F the } + varg =/^www\./; - if(G.test (h)) { $H = h.substr (4) $ } - returnh - }; the if(c = =d) { - return1Wuyi}Else { the varc = This. GetDomain (c); - varb = This. GetDomain (d); Wu if(c = =b) { - return1 About}Else { $c = C.replace (".", "\ \.")); - varA =NewREGEXP ("\ \" + C + "$")); - if(B.match (a)) { - return2 A}Else { + return0 the } - } $ } the};
The third Kind, others ':
1 functionGetpgjs () {2 varAgent =navigator.userAgent.toLowerCase ();3 varres = Agent.match (/android/);4 if(res = = "Android")5 returnRes;6res = Agent.match (/iphone/);7 if(res = = "iphone")8 return"ios";9res = Agent.match (/ipad/);Ten if(res = = "ipad") One return"ios"; Ares = Agent.match (/windows/); - if(res = = "Windows") - return"WP"; the return"PC"; -}
That's all, I'm slowly pondering
Determine the code for the client device: