[英]How can I detect mobile browsers without checking HTTP headers?
Before telling me that the question have been asked earlier only with after reading my title, read further. 在告诉我之前只有在阅读了我的标题之后才提出这个问题之前,请进一步阅读。
I would like to know the best way to detect mobile browser without sniffing the headers for the simple reason that this can be modified addons on a desktop's computer. 我想知道检测移动浏览器而不嗅探头的最佳方法,原因很简单,这可以在桌面计算机上修改插件。
The reason for this is that I am building a HTML5 Game and I do not want it to be played on a desktop's computer. 这样做的原因是我正在构建一个HTML5游戏,我不希望它在桌面计算机上播放。 It will probably end up being played by automated bots if I let this happens.
如果我发生这种情况,它可能最终会被自动机器人播放。
The only way I can think of is to compare Javascript offsetWidth
of document/window
and compare it against a list of possibles sizes. 我能想到的唯一方法是比较
document/window
Javascript offsetWidth
,并将其与可能的大小列表进行比较。 But, I believe that in a not so long future, phones and tablets will have similar screen resolution then desktop's computer and I couldn't take them apart. 但是,我相信在不久的将来,手机和平板电脑的屏幕分辨率将与台式电脑相似,我无法将它们分开。
What are my other options? 我还有什么其他选择? Of course, Javascript is very welcomed.
当然,Javascript非常受欢迎。
If your concern is preventing access from a desktop computer, well, you basically cannot. 如果你的担心是阻止从台式电脑访问,那么你基本上不能。 Headers can be easily forged, beating browser size detection is just a matter of resizing the window... I'd say go with normal user-agent detection and hope for the best.
标题可以很容易伪造,跳动浏览器大小检测只是调整窗口的大小...我会说用普通的用户代理检测并希望最好。
CSS3 makes it better with media queries. CSS3使媒体查询变得更好。 Instead of the if-then-else logic with the device types (User Agents), it allows us to code to the screen size.
它不是使用设备类型(用户代理)的if-then-else逻辑,而是允许我们对屏幕大小进行编码。
The basic idea being, dynamically adapting to the screen size (and other capabilities!) and also making the design of the website future proof from the ground-up. 基本的想法是,动态地适应屏幕尺寸(和其他功能!),并使网站的设计从一开始就是未来的证明。
Maybe one thing you could try is to make some sort of "unlock" touch gesture when your game starts up. 也许您可以尝试的一件事是在游戏启动时进行某种“解锁”触摸手势。 So for example dragging a circle onto an other or something along those lines, which will:
例如,将一个圆圈拖到另一个或沿着这些线的东西上,这将:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.