iOS 7中Safari浏览器的用户代理。

时间:2022-09-15 09:35:53

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.

我想用Safari浏览器打开iPhone和iPod的网站。对于其他浏览器如Chrome,海豚等,它不应该打开。

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?

通过查看crios和Mercury string,我可以看到Chrome浏览器,但是其他浏览器看起来和Safari有相同的用户代理呢?

3 个解决方案

#1


28  

The other answer 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系统中,苹果阻止了所有竞争的浏览器,包括他们自己的渲染引擎;所有人都必须使用标准的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.

因此,所有的第三方浏览器(有诸如syncing favorites之类的功能)都只是在Safari的webview上包装,这实际上是在呈现页面,因此它们都有Safari的用户代理字符串。

#2


5  

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.

所以很有可能是没有办法判断的。

#3


0  

Solves for mercury, opera, chrome n firefox but not dolphin

解决了水星,opera, chrome n firefox,但不是海豚。

(
  (/(iPad|iPhone|iPod)/gi).test(userAgent) &&
  !(/CriOS/).test(userAgent) &&
  !(/FxiOS/).test(userAgent) &&
  !(/OPiOS/).test(userAgent) &&
  !(/mercury/).test(userAgent)
)

#1


28  

The other answer 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系统中,苹果阻止了所有竞争的浏览器,包括他们自己的渲染引擎;所有人都必须使用标准的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.

因此,所有的第三方浏览器(有诸如syncing favorites之类的功能)都只是在Safari的webview上包装,这实际上是在呈现页面,因此它们都有Safari的用户代理字符串。

#2


5  

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.

所以很有可能是没有办法判断的。

#3


0  

Solves for mercury, opera, chrome n firefox but not dolphin

解决了水星,opera, chrome n firefox,但不是海豚。

(
  (/(iPad|iPhone|iPod)/gi).test(userAgent) &&
  !(/CriOS/).test(userAgent) &&
  !(/FxiOS/).test(userAgent) &&
  !(/OPiOS/).test(userAgent) &&
  !(/mercury/).test(userAgent)
)