Example 1
<Script>
Function browserRedirect (){
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 = 'http: // www.111cn.net ';
} Else {
// Window. location. href = 'http: // m.111cn.net ';
}
}
$ (Function (){
BrowserRedirect ();
});
</Script>
Example2
<Script type = "text/javascript">
/*
PC841 adaptive jump
*/
(Function (){
Var reWriteUrl = function (url ){
If (url ){
Var Splits = url. split ("/"), siteName = window. location. pathname;
If (typeof siteName! = "Undefined "){
Return "http://m.111cn.net" + siteName;
}
}
};
If (/Android | webOS | iPhone | iPad | Windows Phone | iPod | BlackBerry | SymbianOS | Nokia | Mobile/I. test (navigator. userAgent )){
Var url = window. location. href;
Var pathname = window. location. pathname;
If (url. indexOf ("? Mobile ") <0 ){
Try {
Window. location. href = reWriteUrl (url );
} Catch (e ){}
}
};
})();
</Script>
Note: If you want to show it to search engines, add it to the file header.
<Meta http-equiv = "mobile-agent" content = "format = xhtml; url = http://m.111cn.net"/>
<Meta http-equiv = "mobile-agent" content = "format = html5; url = http://m.111cn.net"/>
It indicates that the search engine's mobile spider crawls the mobile phone version.