With the popularization of mobile devices, the enterprise's network propaganda can not be limited to the PC side, but also need to build on the mobile side. For the company's website, used to do the PC-side, of course mobile phones and other mobile terminals can also be accessed, but the user experience is certainly not as fully suitable for the convenience of the mobile phone. After we have made a WAP mobile website for our website, if there is a user to visit our Enterprise top-level domain website through mobile phone, then judge jump to the dedicated mobile site.
The first type: Direct JS script
<script type= "Text/javascript" >
try {
var urlhash = Window.location.hash;
if (!urlhash.match ("Fromapp"))
{
if (Navigator.userAgent.match (/(iphone|ipod| Android|ios|ipad)))
{
Window.location= "http://m.lixincpa.cn (change to your own WAP site)";
}
}
}
catch (Err)
{
}</script>
The second kind, a little longer, references
function Uaredirect (murl) {
try {
if (document.getElementById ("bdmark") = null) {
Return
}
var urlhash = Window.location.hash;
if (!urlhash.match ("Fromapp")) {
if (Navigator.userAgent.match (/(iphone|ipod| Android|ios|ipad))) {
Location.replace (Murl);
}
}
} catch (Err) {}
}
The above script is persisted to the Mobile.js file, and then the following 2 JS call files are referenced in the page that needs to be called.
<script src= "Mobile.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >uaredirect ("http://m.lixincpa.cn/(change to your own WAP site)");</script>
Both methods can be used, and my test on Android and iphone is feasible.
below to share a section of PHP to determine the computer access or mobile Access code:
<?php
Mobile page Jump
Returns true if the accessed browser is detected as one of the following specified mobile browsers
function Is_mobile () {
$regex _match= "/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
$regex _match.= "htc|dopod|blazer|netfront|helio|hosin|huawei|novarra| Coolpad|webos|techfaith|palmsource| ";
$regex _match.= "blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom |bunjalloo|maui| ";
$regex _match.= "Symbian|smartphone|midp|wap|phone|windows Ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee |^sie\-|portalmmm| ";
$regex _match.= "jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220";
$regex _match.= ")/I";
return isset ($_server[' http_x_wap_profile ')) or isset ($_server[' http_profile ']) or Preg_match ($regex _match, Strtolower ($_server[' http_user_agent '));
}
$is _mobile=is_mobile ();
if ($is _mobile) {
This is a mobile browser, you can jump to the mobile version of the page
Header ("Location:http://m.lixincpa.cn");
echo "Mobile Access";
}else{
This is not a mobile browser
Header ("Location:http://www.lixincpa.cn");
echo "Computer access";
}
?>
3 Ways to Judge Mobile browser jump WAP Mobile website