iPad 上 iOS 版 Chrome 用户代理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11295189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:05:58  来源:igfitidea点击:

Chrome for iOS user agent on iPad

iosgoogle-chromehttp-headersuser-agent

提问by Brad Robinson

I have a web page that when viewed from an iOS device displays slightly different content. To detect the device in question the site looks for iPad;, iPod;, or iPhone;in the user agent string.

我有一个网页,从 iOS 设备查看时显示的内容略有不同。为了检测有问题的设备的网站查找iPad;iPod;或者iPhone;在用户代理字符串。

This works perfectly on Safari on all iOS devices. Testing with Chrome for iOS it works on iPhone and iPad 1, but not iPad 3. The web site is getting the following (unexpected) user-agent string:

这在所有 iOS 设备上的 Safari 上都能完美运行。使用适用于 iOS 的 Chrome 进行测试,它适用于 iPhone 和 iPad 1,但不适用于 iPad 3。该网站正在获取以下(意外的)用户代理字符串:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.53.11 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10

This seems to be related to the "request desktop site" option in the chrome menu (what would be the wrench icon in desktop chrome). For my site it's disabled and seems to be locked to the desktop rather than mobile site. For other sites, it's enabled and results in a different user-agent string being sent when selected. eg: try http://ifconfig.me/all

这似乎与 chrome 菜单中的“请求桌面站点”选项有关(桌面 chrome 中的扳手图标是什么)。对于我的网站,它被禁用并且似乎被锁定到桌面而不是移动网站。对于其他站点,它已启用并导致在选择时发送不同的用户代理字符串。例如:尝试http://ifconfig.me/all

So my questions are:

所以我的问题是:

  • what criteria does Chrome use to decide whether to enable this option
  • given that Chrome has forced this site to the desktop site, how do I render iOS specific content (in my case a link using a protocol that is handled by my app)
  • Chrome 使用什么标准来决定是否启用此选项
  • 鉴于 Chrome 已将此站点强制为桌面站点,我如何呈现 iOS 特定内容(在我的情况下是使用由我的应用程序处理的协议的链接)

If you'd like to test this yourself, there's a page here that simply reflects the user-agent string.

如果您想自己测试,这里有一个页面可以简单地反映用户代理字符串。

回答by don

The browser will switch between using the two User Agent strings based on whether you are acting as a mobile browser of masquerading as the desktop browser.

浏览器将根据您是否充当伪装成桌面浏览器的移动浏览器在使用两个用户代理字符串之间切换。

User Agent:

用户代理:

Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-gb)
AppleWebKit/534.46.0 (KHTML, like Gecko)
CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3

User Agent after "Request desktop version":

“请求桌面版本”后的用户代理:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3)
AppleWebKit/534.53.11 (KHTML, like Gecko)
Version/5.1.3 Safari/534.53.10

This is only a hint to the web server about who the client is. The browser should render the received web content independently of the User Agent.

这只是向 Web 服务器提示有关客户端是谁的提示。浏览器应该独立于用户代理呈现接收到的 Web 内容。