简体   繁体   English

检查用户是否为移动设备的简单方法?

[英]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.

相关问题 有没有办法检测移动设备是否启用了JavaScript启用的位置服务? - Is there a way to detect whether or not mobile device has location services enabled with JavaScript? 确定用户是否在移动设备上的最简单方法 - Easiest way to determine if user is on mobile device 是否有一种简短的方法来检查用户输入是否以数组中的一个元素结尾? - Is there a short way to check whether the user input ends with one of the elements in an array? 检查设备在Flask中是否可移动 - Check if device is mobile in Flask 如何检查我的 React PWA 是否已安装在设备(桌面/Android/IOS)上以自定义用户体验? - How to check whether my React PWA is already installed on the device(Desktop/Android/IOS) to customize the user Experience? 有没有办法检查javascript或php中的客户端设备的信息,哪些请求到服务器? 这个设备是手机,平板电脑还是电脑? - is there any way to check the information of client device in javascript or php, which request to server? is this device mobile, tablet or pc? 如何检查用户是否为管理员? - How to check whether a user is admin or not? 记住移动设备中的登录用户 - Remember the logged in user in mobile device 测试元素是否在前面的简单方法? - Simple way to test whether an element is in front? 如何检查正在使用我的网站的设备是否是移动用户 - How can I check if the device, which is using my website, is a mobile user or not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM