[英]Simple way to check whether user is mobile device?
I'm looking to create a simple redirect on my homepage for users of major mobile OS (at least Android, Nokia/Symbian, Windows, iOS and Blackberry OS). 我正在为主要移动操作系统(至少是Android,诺基亚/ Symbian,Windows,iOS和Blackberry OS)的用户在主页上创建一个简单的重定向。
At present I have it working for iPhone / iPod (see below), but I'm wondering whether there's a simple way in javascript to check for all. 目前,我可以在iPhone / iPod上使用它(请参阅下文),但是我想知道javascript中是否有一种简单的方法可以检查所有内容。 (As opposed to just writing out a big ol list of mobile userAgents). (而不是仅仅列出大量的移动userAgent列表)。
Perhaps something that detects screensize? 也许可以检测屏幕尺寸的东西?
// Current Code
<script type="text/javascript">
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
if (document.cookie.indexOf("iphone_redirect=false") == -1) {
window.location = "http://m.domain.co.nz";
}
}
</script>
这是在服务器上而不是在客户端上正确完成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.