先我们来看看一段用php如何识别用户是通过 PC、iPad 还是手机来访问网站?
$uAgent = $_SERVER['HTTP_USER_AGENT'];
$osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|XWindow|ubuntu|Longhorn|AIX|Linux|AmigaOS|BEOS|HP-UX|OpenBSD|FreeBSD|NetBSD|OS/2|OSF1|SUN";
if(preg_match("/($osPat)/i", $uAgent ))
{
echo "来着PC访问";
}
else
{
echo "其他终端访问";
}
?>
以下是腾讯的通过JS语句判断WEB网站的访问端是电脑还是手机
腾讯网的适配代码
如何判断访问网站的机器类型-如何判断ipad
JS 判断浏览器客户端类型(ipad,iphone,android)
腾讯网的适配代码
如何判断访问网站的机器类型-如何判断ipad
如何判断是否是 iPad 浏览器呢,关键是看它的 User Agent 中是否有 iPad。iPad 使用的是 Safari Mobile 浏览器,他的的 User Agent 是:
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
function is_iPad(){
[object Object] [object Object] [object Object]var ua = navigator.userAgent.toLowerCase();
[object Object] [object Object] [object Object]if(ua.match(/iPad/i)=="ipad") {
[object Object] [object Object] [object Object] [object Object] [object Object] [object Object]return true;
[object Object] [object Object] [object Object]} else {
[object Object] [object Object] [object Object] [object Object] [object Object] [object Object]return false;
[object Object] [object Object] [object Object]}
}
$is_iPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.fairyfish.net [R=301]
JS 判断浏览器客户端类型(ipad,iphone,android)