Javascript 检查用户在网站上使用的平台
我有一个网站。我想知道,如果他来过我的网站,他正在使用哪个用户。例如iOS、Android、Windows phone、Windows pc。特别是iOS,我想检查他是在iPhone上还是现在在javaScript上:Javascript 检查用户在网站上使用的平台,javascript,web,Javascript,Web,我有一个网站。我想知道,如果他来过我的网站,他正在使用哪个用户。例如iOS、Android、Windows phone、Windows pc。特别是iOS,我想检查他是在iPhone上还是现在在javaScript上: library for detecting mobile clients here: http://mobiledetect.net include 'Mobile_Detect.php'; $detect = new Mobile_Detect(); // Che
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
使用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());
}
}) 用户代理字符串应该告诉您,但请注意,它可能会被欺骗或忽略。如果你正在收集统计数据,这很好,但如果你依赖它进行浏览器嗅探,那么你可能会积累麻烦。事实上,其中一个功能与iOS不兼容。我只是想让他们知道这在你的手机上不起作用。