Microsoft Edge的用户代理字符串名称是什么? [英] What is the User Agent string name for Microsoft Edge?

查看:808
本文介绍了Microsoft Edge的用户代理字符串名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个网站,我希望它与即将推出的Microsoft Edge兼容.更具体地说,它是移动版本.是否有人知道哪个字符串将标识Edge Mobile浏览器(例如,"IE Mobile"标识Internet Explorer的移动版本).

I'm making a website and I want it to be compatible with the forthcoming Microsoft Edge when it comes out officially. To be more specific, the mobile version of it. Does anyone know what string will identify the Edge Mobile Browser (for example, "IE Mobile" identifies the mobile version of the Internet Explorer).

推荐答案

Microsoft Edge UA字符串:

Mozilla/5.0(Windows NT 10.0)AppleWebKit/537.36(KHTML,例如Gecko)Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136

我会详细说明为什么博客文章.

Neowin最近报告说,Microsoft的Windows 10新浏览器Spartan使用Chrome UA字符串,"Mozilla/5.0(Windows NT 10.0; WOW64)AppleWebKit/537.36(KHTML,例如Gecko)Chrome/39.0.2171.71 Safari/537.36 Edge/12.0. 这是有目的的.

Neowin recently reported that Microsoft’s new browser for Windows 10, Spartan, uses the Chrome UA string, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0″. That is done on purpose.

您还会注意到,整个字符串以"Edge/12.0"结尾,而Chrome则没有.

You’ll also notice that the entire string ends with "Edge/12.0″, which Chrome does not.

我应该指出,这与Microsoft在Windows 8上读取的IE 11并没有太大的不同,例如Gecko等Mozilla/5.0(Windows NT 6.3; Trident/7.0; rv:11.0),如下所示:在这篇文章中进行了解释.

I should point out, that this isn’t a radical departure from what Microsoft did with IE 11, which on Windows 8 reads: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko, as explained in this post.

什么是用户代理嗅探?

通常,Web开发人员会通过UA嗅探来检测浏览器. Mozilla在其博客中对此进行了很好的解释:

Often, web developers will UA sniffing for browser detection. Mozilla explains it well on their blog:

为不同的浏览器提供不同的网页或服务是 通常是个坏主意.网络意味着所有人都可以使用, 不论他们使用的是哪种浏览器或设备.有办法 开发您的网站以根据以下内容逐步增强自身能力: 功能的可用性,而不是针对特定的浏览器.

Serving different Web pages or services to different browsers is usually a bad idea. The Web is meant to be accessible to everyone, regardless of which browser or device they’re using. There are ways to develop your web site to progressively enhance itself based on the availability of features rather than by targeting specific browsers.

这是一篇很棒的文章,解释了用户代理的历史.

通常,懒惰的开发人员只会嗅探UA字符串,并根据他们认为查看器正在使用的浏览器来禁用其网站上的内容.对于开发人员来说,Internet Explorer 8是一个令人沮丧的常见问题,因此他们将经常检查用户是否正在使用IE的任何版本,并禁用功能.

Often, lazy developers will just sniff for the UA string and disable content on their website based on which browser they believe the viewer is using. Internet Explorer 8 is a common point of frustration for developers, so they will frequently check if a user is using ANY version of IE, and disable features.

Edge团队在博客上更详细地介绍了这一点.

所有用户代理字符串都包含比您使用的实际浏览器更多的其他浏览器信息–不仅是令牌,还包括有意义的"版本号.

All user agents strings contain more information about other browsers than the actual browser you are using – not just tokens, but also ‘meaningful’ version numbers.

Internet Explorer 11的UA字符串:

像Gecko一样的Mozilla/5.0(Windows NT 6.3; Trident/7.0; rv:11.0)

Microsoft Edge UA字符串:

Mozilla/5.0(Windows NT 10.0)AppleWebKit/537.36(KHTML,例如Gecko)Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136

Patrick H. Lauke在W3C讨论中将userAgent属性恰当地描述为一个不断增长的谎言". (或者说,一种平衡的做法是添加足够的旧关键字,这些旧关键字不会立即使旧的UA嗅探代码掉落,同时仍在尝试传达一些实际有用和准确的信息."

The userAgent property has been aptly described as "an ever-growing pack of lies" by Patrick H. Lauke in W3C discussions. ("or rather, a balancing act of adding enough legacy keywords that won’t immediately have old UA-sniffing code falling over, while still trying to convey a little bit of actually useful and accurate information.")

我们建议Web开发人员尽可能避免UA监听;现代化的Web平台功能几乎可以通过简单的方式检测到.例如, Modernizr 库是一种检测特征的绝佳且简单的方法.

We recommend that web developers avoid UA sniffing as much as possible; modern web platform features are nearly all detectable in easy ways. For example, the Modernizr library is a fantastic and simple way of detecting features.

在过去的一年中,我们已经看到一些UA嗅探网站,这些网站已经过更新,可以检测Microsoft Edge……只是为其提供了旧版IE11代码路径.这不是最佳方法,因为Microsoft Edge会匹配"WebKit"行为,而不是IE11行为(Edge-WebKit的任何差异都是我们有兴趣修复的错误).

Over the past year, we’ve seen some UA-sniffing sites that have been updated to detect Microsoft Edge… only to provide it with a legacy IE11 code path. This is not the best approach, as Microsoft Edge matches ‘WebKit’ behaviors, not IE11 behaviors (any Edge-WebKit differences are bugs that we’re interested in fixing).

根据我们的经验,Microsoft Edge在这些站点的"WebKit"代码路径上运行得最好.另外,随着互联网在各种设备上的普及,请假定使用未知的浏览器是不错的选择–请不要将您的网站限制为只能在一小部分当前已知的浏览器上运行.如果这样做,将来您的网站几乎肯定会崩溃.

In our experience Microsoft Edge runs best on the ‘WebKit’ code paths in these sites. Also, with the internet becoming available on a wider variety of devices, please assume unknown browsers are good – please don’t limit your site to working only on a small set of current known browsers. If you do this, your site will almost certainly break in the future.

结论

通过显示Chrome UA字符串,我们可以解决这些开发人员正在使用的hack,从而为用户提供最佳体验.

By presenting the Chrome UA string, we can work around the hacks these developers are using, to present the best experience to users.

这篇关于Microsoft Edge的用户代理字符串名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆