让网站检测我们的移动浏览器
我被要求找到一种明智的方法,使大多数流行网站将我们的浏览器检测为“移动”浏览器——功能完整,但在相当有限的硬件上运行。这个想法是,最流行的网站似乎都有移动版本,渲染速度更快并且更适合屏幕。
我查看了反问题,它告诉我没有明显的标准方法 - http://www.brainhandles.com/techno-thoughts/Detecting-mobile-browsers 就是一个很好的例子。通过查看流行的移动和桌面浏览器中的各种用户代理字符串可以证实这一点。
到目前为止,我们能想到的最好主意是在字符串中的某处添加“Mobile”,因为这是 iPad/iPhone 版 Safari 和 Windows/Mac 版 Safari 之间的主要明显区别。有人有更好的主意吗?
I've been asked to find out a sensible way to make the majority of popular websites detect our browser - which is functionally complete, but is running on rather constrained hardware - as a "mobile" browser. The idea is that the heaviest popular websites seem to have mobile versions, which render much faster and fit better on the screen.
I've looked at the inverse question, which tells me that there isn't an obvious standard way of doing it - http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers is a case in point. This is borne out by looking at a variety of User-Agent strings from popular mobile and desktop browsers.
So far the best idea we can come up with is to add "Mobile" to the string somewhere, since this is the main visible difference between Safari for iPad/iPhone and for Windows/Mac. Does anyone have a better idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这行不通。绝大多数移动电话的用户代理中不包含“Mobile”。 这是一个相当大的移动用户代理列表。正如您所看到的,没有一致性。最重要的是,每周都会向市场添加新的用户代理。
This won't work. The vast majority of mobile phones don't include "Mobile" in their user agents. Here's a fairly huge list of mobile user agents. As you can see, there's no consistency. On top of that, new user agents are being added to the market on a weekly basis.
如果唯一标识您自己并不重要,您可以简单地复制流行移动设备的用户代理字符串的重要部分...这将是任何移动检测脚本中明显的遗漏。
If uniquely identifying yourself is unimportant you could simply copy the important parts of the User Agent string for a popular mobile device... one which would be an obvious omission from any mobile detection script.