Common code on the Web
/**
* [ismobile judgment Platform]
* @param test: 0:iphone 1:android
/function IsMobile (test) {
var U = navigator.useragent, app = navigator.appversion;
if (/applewebkit.*mobile/i.test (navigator.useragent) | | (/midp| symbianos| nokia| Samsung| Lg| nec| tcl| alcatel| bird| dbtel| dopod| philips| haier| lenovo| mot-| nokia| sonyericsson| sie-| amoi| Zte/.test (navigator.useragent)) {
if (window.location.href.indexOf ("? mobile") <0) {
try{
if (/ Iphone|mac|ipod|ipad/i.test (navigator.useragent)) {return
' 0 ';
} else{return
' 1 ';
}
} catch (e) {}
}
}else if (u.indexof (' IPad ') >-1) {return
' 0 ';
} else{return
' 1 ';
}
;
How to use:
var pla=ismobile (1);
If the PLA is returning 0:iphone 1:android
Code One,
<script type = "text / javascript">
var browser = {
versions: function () {
var u = navigator.userAgent, app = navigator.appVersion;
return {// Mobile terminal browser version information
trident: u.indexOf ('Trident')> -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 core
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 terminal
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, // Is it an iPhone or QQHD browser
iPad: u.indexOf ('iPad')> -1, // whether iPad
webApp: u.indexOf ('Safari') == -1 // Whether the web should be program, without head and bottom
};
} (),
language: (navigator.browserLanguage || navigator.language) .toLowerCase ()
}
if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios) {
window.location.href = "http://www.jb51.net";
}
if (browser.versions.android) {
window.location.href = "http://www.qq.com";
}
</ script>
The key to deciding whether to be an ipad browser is to see if there is an ipad in its User Agent. The IPad uses the Safari Mobile browser, and his 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 to Judge Ipad,iphone,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 = 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) {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 parameter value var surl = window.location.search.substr (1);
var r = Surl.match (new RegExp (^|&) + name + = ([^&]*) (&|$)));
return (r = = null Null:unescape (r[2]);
The function Fshowverblock () {if (BFORCEPC) {document.getElementById ("Dv_block"). Style.display = "block";
} else{document.getElementById ("Ad_block"). Style.display = "block";
} fbrowserredirect (); </script>