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

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

问题描述

我正在制作一个网站,我希望它在正式发布时与即将推出的 Microsoft Edge 兼容.更具体地说,它的移动版本.有谁知道用什么字符串来标识Edge Mobile Browser(例如,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 最近报道称,微软的 Windows 10 新浏览器 Spartan 使用 Chrome UA 字符串,Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71Safari/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 对 IE 11 所做的并没有根本的不同,IE 11 在 Windows 8 上显示为:Mozilla/5.0(Windows NT 6.3;Trident/7.0;rv:11.0),如 Gecko,如在这篇文章中进行了解释.

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 字符串:

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

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

在 W3C 讨论中,Patrick H. Lauke 恰当地将 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 嗅探;现代网络平台功能几乎都可以通过简单的方式检测到.例如,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 字符串,我们可以解决这些开发人员使用的黑客攻击,为用户提供最佳体验.

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天全站免登陆