Based on the browser type of the mobile client, js redirects to the official website/mobile website and multiple instance codes. js redirects
Instance 1: relatively simple and crude, lack of point type judgment
<script type="text/javascript"> var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM ){ window.location.href="3g.php"; } </script>
Example 2: Code neat, many functions are based on this added Function
<Script> var pc_style = "" var browser = {versions: function () {var u = navigator. userAgent, app = navigator. appVersion; return {trident: u. indexOf ('think')>-1, presto: u. indexOf ('presto ')>-1, webKit: u. indexOf ('applewebkit ')>-1, gecko: u. indexOf ('gecko ')>-1 & u. indexOf ('html ') =-1, mobile :!! U. match (/AppleWebKit. * Mobile. */) | !! U. match (/AppleWebKit/) & u. indexOf ('qihu') & u. indexOf ('qihu')>-1 & u. indexOf ('chromi') <0, ios :!! U. match (/\ (I [^;] +; (U ;)? CPU. + Mac OS X/), android: u. indexOf ('android')>-1 | u. indexOf ('linux ')>-1, iPhone: u. indexOf ('iphone ')>-1 | u. indexOf ('mac')>-1, iPad: u. indexOf ('ipad ')>-1, webApp: u. indexOf ('safari ') =-1, ua: u };} (), language: (navigator. browserLanguage | navigator. language ). toLowerCase ()} if (browser. versions. mobile &&! Browser. versions. iPad) {this. location = "Enter the address of the page to jump to the micro-site" ;}</script>
Instance 3. Added some features
<! -- Start smartphone judgment --> <! -- <Script type = "text/javascript" language = "javascript"> Function. prototype. bind = function (bindObj, args) {var _ self = this; return function () {return _ self. apply (bindObj, []. concat (args) }}; function $ (id) {return "string" = typeof id? Document. getElementById (id): id ;}; var browser = {versions: function () {var u = navigator. userAgent, app = navigator. appVersion; return {trident: u. indexOf ('think')>-1, presto: u. indexOf ('presto ')>-1, webKit: u. indexOf ('applewebkit ')>-1, gecko: u. indexOf ('gecko ')>-1 & u. indexOf ('html ') =-1, mobile :!! U. match (/AppleWebKit. * Mobile. */) | !! U. match (/AppleWebKit/), ios :!! U. match (/\ (I [^;] +; (U ;)? CPU. + Mac OS X/), android: u. indexOf ('android')>-1 | u. indexOf ('linux ')>-1, iPhone: u. indexOf ('iphone ')>-1 | u. indexOf ('mac')>-1, iPad: u. indexOf ('ipad ')>-1, webApp: u. indexOf ('safari ') =-1, QQbrw: u. indexOf ('mqqbrowser ')>-1, ucLowEnd: u. indexOf ('ucweb7. ')>-1, ucSpecial: u. indexOf ('rv: 1.2.3.4 ')>-1, ucweb: function () {try {return parseFloat (u. match (/ucweb \ d + \. \ d +/gi ). toString (). Match (/\ d + \. \ d + /). toString ()> = 8.2} catch (e) {if (u. indexOf ('uc')>-1) {return true;} else {return false ;}}(), Symbian: u. indexOf ('symbian ')>-1, ucSB: u. indexOf ('Firefox/1. ')>-1 };}()} var _ gaq = _ gaq | []; (function (win, browser, undefined) {var rf = document. referrer; if (rf = "" | rf. toLocaleLowerCase (). indexOf (".xiu.com") =-1) {var defaultJumpDomain = ""; if (defajumjumpdomain =" Www ") {return;} if (defaultJumpDomain =" m ") {window. location. href =" http://wap.xiu.com /? From = pc "; return;} if (screen = undefined | screen. width <810) {if (browser. versions. iPad = true) {return;} if (browser. versions. webKit = true | browser. versions. mobile = true | browser. versions. ios = true | browser. versions. iPhone = true | browser. versions. ucweb = true | browser. versions. ucSpecial = true) {win. location. href = "http://wap.xiu.com /? From = pc "; return;} if (browser. versions. symbian) {win. location. href = "http://wap.xiu.com/" ;}}}) (window, browser); </script> --> <! -- Smart phone determines the end -->
Example 4: It is recommended to use the simple help house. If you have better code, you can share it.
<Script type = "text/javascript"> var browser = {versions: function () {var u = navigator. userAgent, app = navigator. appVersion; return {trident: u. indexOf ('think')>-1, presto: u. indexOf ('presto ')>-1, webKit: u. indexOf ('applewebkit ')>-1, gecko: u. indexOf ('gecko ')>-1 & u. indexOf ('html ') =-1, mobile :!! U. match (/AppleWebKit. * Mobile. */) | !! U. match (/AppleWebKit/), ios :!! U. match (/\ (I [^;] +; (U ;)? CPU. + Mac OS X/), android: u. indexOf ('android')>-1 | u. indexOf ('linux ')>-1, iPhone: u. indexOf ('iphone ')>-1 | u. indexOf ('mac')>-1, iPad: u. indexOf ('ipad ')>-1, webApp: u. indexOf ('safari ') =-1, QQbrw: u. indexOf ('mqqbrowser ')>-1, weiXin: u. indexOf ('micromessenger ')>-1, ucLowEnd: u. indexOf ('ucweb7. ')>-1, ucSpecial: u. indexOf ('rv: 1.2.3.4 ')>-1, ucweb: function () {try {return parseFloat (u. match (/ucweb \ d + \. \ d +/gi ). toString (). match (/\ d + \. \ d + /). toString ()> = 8.2} catch (e) {if (u. indexOf ('uc')>-1) {return true;} else {return false ;}}(), Symbian: u. indexOf ('symbian ')>-1, ucSB: u. indexOf ('Firefox/1. ')>-1 };}(), liulanqi: navigator. userAgent} if (browser. versions. QQbrw) {document. write ("qq Browser");} else {document. write ("other browsers" + browser. liulanqi) ;}</script>