One, JS implementation
Window.onload=function () {
var mobileagent = new Array ("iphone", "ipod", "ipad", "Android", "mobile", "BlackBerry", "webOS",
"Incognito", "webmate", "Bada", "Nokia", "LG", "UCWeb", "Skyfire");
var browser = Navigator.userAgent.toLowerCase ();
var ismobile = false;
for (var i=0; i<mobileagent.length; i++) {
if (Browser.indexof (Mobileagent[i])!=-1) {ismobile = true;
Alert (Mobileagent[i]);
Location.href = ' http://www.111cn.net ';
Break
}
}
}
<title> Testing </title>
<meta Charset=utf8/>
<body>
<?php Echo ' Hello Wap '?>
<script src=./test.js></script>
</body>
Test: When http://test92.sinaapp.com/is opened with PC, show Hello WAP, when accessing with mobile device, will jump www.111cn.net. (You can test the mobile-side access site directly in Chrome)
Second, PHP implementation
PHP detects mobile devices with the help of a mobile detection class library. Mobile detection class Library download address: Https://github.com/dwqs/Mobile-Detect
<title> Testing </title>
<meta Charset=utf8/>
<body>
<p>mobile_detect.php Identification Cell Phone </p>
<?php
Require_once "mobile_detect.php";
$detect = new Mobile_detect;
if ($detect->ismobile ()) {
echo "<script>location.href= ' http://www.ido321.com/' </script>";
}
?>
</body>
Testing: http://www.111cn.net/can also individually identify mobile systems and devices
All tablet devices
if ($detect->istablet ()) {
}
is a mobile but not a flatbed device
if ($detect->ismobile () &&! $detect->istablet ()) {
}
iOS system
if ($detect->isios ()) {
}
Android system
if ($detect->isandroidos ()) {
}
WindowsPhone system
if ($detect->iswindowsphoneos ()) {
}