简体   繁体   English

如何在不检查HTTP标头的情况下检测移动浏览器?

[英]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逻辑,而是允许我们对屏幕大小进行编码。

Here is good read. 是很好的阅读。

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. 基本的想法是,动态地适应屏幕尺寸(和其他功能!),并使网站的设计从一开始就是未来的证明。

Some conceptual examples are HERE 一些概念性的例子是HERE

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: 例如,将一个圆圈拖到另一个或沿着这些线的东西上,这将:

  1. require touch events to be fired by the browser 要求浏览器触发触摸事件
  2. can be slightly different positions / sizes every time so difficult to script. 每次都可能略有不同的位置/大小,因此难以编写脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能“性能检测”浏览器 - How can I “performance detect” browsers javascript是否可以检测滚动条何时不可用(即在移动浏览器上)? - Can javascript detect when scrollbars are unavailable (i.e. on mobile browsers)? 是否可以通过JavaScript或HTTP标头检测*“移动设备”的类型? - Possible to detect the *type of mobile device* via javascript or HTTP Headers? 如何检测浏览器是否是移动浏览器并在普通浏览器和移动浏览器之间切换? - How can I detect if a browser is mobile and switch between normal and mobile? 检测没有移动的浏览器? - Detect browsers that AREN'T mobile? 有没有检测移动浏览器的好方法? - Is there an elegant way to detect mobile browsers? 检测移动浏览器:如何将以下内容重写为if AND else语句? - Detect Mobile Browsers: How to rewrite the following into an if AND else statement? 如何以最大的兼容性检测台式机和移动浏览器的宽度 - How to detect desktop and mobile browsers width with maximum compataibility 如何清除AJAX GET调用的HTTP标头? - How can I clear HTTP headers for AJAX GET calls? 如何在移动浏览器上检测退出意图? - How can I detect exit intent on a mobile browser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM