iOS 7 上 Safari 浏览器的用户代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19264114/
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
User Agent for Safari browser on iOS 7
提问by Novice User
I want to open my site only in iPhone and iPod with Safari browser. For any other browser like Chrome, Dolphin, etc, It shouldn't open.
我只想在 iPhone 和 iPod 中使用 Safari 浏览器打开我的网站。对于 Chrome、Dolphin 等任何其他浏览器,它不应该打开。
But currently I am getting the same user agent from almost all the devices:
但目前我从几乎所有设备上获得了相同的用户代理:
For Safari:
对于 Safari:
User Agent String :: mozilla/5.0 (iphone; cpu iphone os 7_0_2 like mac os x) applewebkit/537.51.1 (khtml, like gecko) version/7.0 mobile/11a501 safari/9537.53
For Chrome:
对于铬:
User Agent String :: mozilla/5.0 (iphone; cpu iphone os 7_0_2 like mac os x) applewebkit/537.51.1 (khtml, like gecko) crios/30.0.1599.16 mobile/11a501 safari/8536.25
For Mercury browser:
对于水星浏览器:
User Agent String :: mozilla/5.0 (iphone; cpu iphone os 6_0_1 like mac os x) applewebkit/536.26 (khtml, like gecko) mercury/7.4.2 mobile/10a523 safari/8536.25
For Dolphin browser:
对于海豚浏览器:
User Agent String :: mozilla/5.0 (iphone; cpu iphone os 7_0_2 like mac os x) applewebkit/537.51.1 (khtml, like gecko) version/6.0 mobile/10a523 safari/8536.25
With Chrome I can see by checking for crios
, and Mercury by mercury
string, but what about the other browsers which seem to have same user agent as Safari?
使用 Chrome,我可以通过检查字符串来查看crios
和 Mercury mercury
,但是其他浏览器似乎与 Safari 具有相同的用户代理呢?
回答by Andy Nugent
The otheranswer isn't strictly correct. On iOS, Apple block any competing browsers from actually including their own rendering engine; all must use the standard webview.
在其他的答案是不完全正确。在 iOS 上,Apple 阻止任何竞争浏览器实际包含他们自己的渲染引擎;所有人都必须使用标准的 webview。
So all of those 3rd party browsers (with functionality such as syncing favourites, etc.) are simply wrappers around the Safari powered webview that's actually rendering the page, hence them all having Safari's user agent string.
因此,所有这些 3rd 方浏览器(具有同步收藏夹等功能)只是围绕实际呈现页面的 Safari 驱动的 webview 的简单包装,因此它们都具有 Safari 的用户代理字符串。
回答by ksimons
The browsers do this very deliberately to prevent people from doing what you're trying to do. Their developers feel that since they're using the same web engine (WebKit, blink or gecko) as the others that they'll lkely render pages optimized for similar browsers just fine (which is likely true).
浏览器会非常刻意地这样做,以防止人们做您想做的事情。他们的开发人员认为,由于他们使用与其他人相同的 Web 引擎(WebKit、blink 或 gecko),因此他们可能会呈现针对类似浏览器优化的页面就好了(这可能是真的)。
So most likely there is no way to tell.
所以很可能没有办法告诉。
回答by aWebDeveloper
Solves for mercury, opera, chrome n firefox but not dolphin
解决汞、歌剧、铬 n firefox 但不解决海豚
(
(/(iPad|iPhone|iPod)/gi).test(userAgent) &&
!(/CriOS/).test(userAgent) &&
!(/FxiOS/).test(userAgent) &&
!(/OPiOS/).test(userAgent) &&
!(/mercury/).test(userAgent)
)