我有一个网站。如果他来到我的网站,我想知道他正在使用哪个用户。例如。 iOS,Android,Windows手机,Windows PC。特别是对于iOS,我想检查他是在iPhone还是现在
答案 0 :(得分:6)
使用Javascript: http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-使用-javascript /.
var isMobile = {
Android: function()
{
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function()
{
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function()
{
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function()
{
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function()
{
return navigator.userAgent.match(/IEMobile/i);
},
any: function()
{
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
答案 1 :(得分:1)
library for detecting mobile clients here: http://mobiledetect.net
include 'Mobile_Detect.php';
$detect = new Mobile_Detect();
// Check for any mobile device.
if ($detect->isMobile())
// mobile content
else