javascript 为什么 IE 8 navigator.userAgent 返回 MSIE 7.0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7774690/
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-10-26 01:16:39  来源:igfitidea点击:

Why does IE 8 navigator.userAgent return MSIE 7.0?

javascripthtmlinternet-explorer-8user-agentnavigator

提问by Sun

I am trying to implement a browser support feature on my webpage. For Firefox 3.6 it is working fine, but for some reason IE 8's userAgent is returning a wrong value.

我正在尝试在我的网页上实现浏览器支持功能。对于 Firefox 3.6,它工作正常,但由于某种原因,IE 8 的 userAgent 返回了错误的值。

Here is the scenario, when I run a 'local' javascript code on IE8, navigator.userAgent returns correct information (MSIE 8.0). But when I run this script on a server, it returns MSIE 7.0 on an IE 8 browser.

这是场景,当我在 IE8 上运行“本地”javascript 代码时,navigator.userAgent 返回正确的信息(MSIE 8.0)。但是,当我在服务器上运行此脚本时,它会在 IE 8 浏览器上返回 MSIE 7.0。

Any ideas?

有任何想法吗?

采纳答案by jgritty

Microsoft provides this page:

Microsoft 提供此页面:

http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx

According to the Javascript sample one would think IE8 would return an 8, not a 7.

根据 Javascript 示例,人们会认为 IE8 会返回 8,而不是 7。

回答by Maneesh

You need to check Trident token too.

您也需要检查 Trident 令牌。

Trident token

三叉戟令牌

When the F12 developer tools are used to change the browser mode of Internet Explorer, the version token of the user-agent string is modified to appear so that the browser appears to be an earlier version. This is done to allow browser specific content to be served to Internet Explorer and is usually necessary only when websites have not been updated to reflect current versions of the browser.

使用F12开发者工具更改Internet Explorer的浏览器模式时,修改user-agent字符串的版本令牌出现,使浏览器看起来是较早的版本。这样做是为了允许将特定于浏览器的内容提供给 Internet Explorer,并且通常只有在网站尚未更新以反映当前浏览器版本时才需要这样做。

When this happens, a Trident token is added to the user-agent string. This token includes a version number that enables you to identify the version of the browser, regardless of the current browser mode.

发生这种情况时,会将 Trident 令牌添加到用户代理字符串中。此令牌包含一个版本号,可让您识别浏览器的版本,而不管当前浏览器模式如何。

MORE : http://msdn.microsoft.com/en-us/library/ms537503.aspx

更多:http: //msdn.microsoft.com/en-us/library/ms537503.aspx

回答by Luke Berry

Are you sure you aren't running in IE7 mode? You can change it somewhere in the Developer settings (F12, I think).

你确定你不是在 IE7 模式下运行吗?您可以在开发人员设置中的某处更改它(我认为是 F12)。