Js determines the mobile phone end (Android or iPhone) and androidiphone
Code 1,
<Script type = "text/javascript"> var browser = {versions: function () {var u = navigator. userAgent, app = navigator. appVersion; return {// mobile terminal browser version information trident: u. indexOf ('think')>-1, // IE kernel presto: u. indexOf ('presto ')>-1, // opera kernel webKit: u. indexOf ('applewebkit ')>-1, // Apple, Google kernel gecko: u. indexOf ('gecko ')>-1 & u. indexOf ('khtml ') =-1, // Firefox kernel mobile :!! U. match (/AppleWebKit. * Mobile/I) | !! U. match (/MIDP | SymbianOS | NOKIA | SAMSUNG | LG | NEC | TCL | Alcatel | BIRD | DBTEL | Dopod | PHILIPS | HAIER | LENOVO | MOT-| Nokia | SonyEricsson | SIE- | Amoi | ZTE /), // whether it is a mobile device ios :!! U. match (/\ (I [^;] +; (U ;)? CPU. + Mac OS X/), // ios terminal android: u. indexOf ('android')>-1 | u. indexOf ('linux ')>-1, // android terminal or uc browser iPhone: u. indexOf ('iphone ')>-1 | u. indexOf ('mac')>-1, // whether the browser is iPhone or QQHD iPad: u. indexOf ('ipad ')>-1, // whether iPad webApp: u. indexOf ('safari ') =-1 // whether the web should program, no header and bottom};} (), language: (navigator. browserLanguage | navigator. language ). toLowerCase ()} if (browser. versions. iPhone | browser. versions. iPad | browser. versions. ios) {window. location. href = "http://www.bkjia.com";} if (browser. versions. android) {window. location. href = "http://www.qq.com" ;}</script>
The key to determining whether the browser is an iPad browser is whether the User Agent contains an iPad. The iPad uses the Safari Mobile browser, whose User Agent is:
Mozilla/5.0 (iPad; U; cpu OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
Javascript code
Function is_iPad (){
Var ua = navigator. userAgent. toLowerCase ();
If (ua. match (/iPad/I) = "ipad "){
Return true;
} Else {
Return false;
}
}
Therefore, the code for judging ipad, iphone, and android is:
<Script type = "text/javascript"> var bForcepc = fGetQuery ("dv") = "pc"; function fBrowserRedirect () {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 = sUserAg Ent. 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) {var sUrl = location. href; if (! BForcepc) {window. location. href = "http://m.jb51.net /? Ipad ";}} if (bIsIphoneOs | bIsAndroid) {var sUrl = location. href; if (! BForcepc) {window. location. href = "http://m.jb51.net /? Iphone ";}} if (bIsMidp | bIsUc7 | bIsUc | bIsCE | bIsWM) {var sUrl = location. href; if (! BForcepc) {window. location. href = "http://m.jb51.net/" ;}}function fGetQuery (name) {// get the parameter value var sUrl = window. location. search. substr (1); var r = sUrl. match (new RegExp ("(^ | &)" + name + "= ([^ &] *) (& | $)"); return (r = null? Null: unescape (r [2]);} function fShowVerBlock () {if (bForcepc) {document. getElementById ("dv_block "). style. display = "block";} else {document. getElementById ("ad_block "). style. display = "block" ;}}fbrowserredirect (); </script>