检测IE版本不考虑兼容模式 [英] Detecting IE version not considering compatibility mode
问题描述
我正在试图弄清楚是否可以检测到您使用的是哪个版本的IE,而不是您的文档模式。它可以是服务器或客户端代码(无所谓),我只需要知道用户安装了哪个版本的IE。
I'm trying to figure out if it's possible to detect what version of IE you are using, and not your document-mode. It can be server or client-code (doesn't matter), I just need to know what version of IE the user has installed.
推荐答案
通过检查User-Agent字符串,可以在两者中检测到它。请注意,浏览器可以欺骗他们的UA字符串,但现在比过去更少见。对于较旧的UA字符串,请参阅 MSDN上的这篇文章 。
It could be detected in both, by examining the User-Agent string. Note that browsers can spoof their UA string, but this is rarer now than in the past. See this article on MSDN for older UA strings.
另请注意,IE8在兼容模式和标准模式下发送不同的UA字符串(参见这个和这个 - 两者都是IE8,虽然前者说 MSIE 7.0
)。
Note also that IE8 sends a different UA string in Compatibility mode and in Standards mode (see this and this - both are IE8, although the former says MSIE 7.0
).
参见这个用于很长的UA字符串列表 - 请注意,您应该查找模式,而不是完全匹配,因为已安装的软件将修改UA字符串。
See this for a long list of UA strings - note that you should be looking for a pattern, not exact match, as installed software will modify the UA string.
IE9有一些新的UA字符串 - 有关详细信息,请参阅IEBlog 。
IE9 has some new UA string thing - see the IEBlog for details.
总结(并借鉴 @EricLaw 的评论):
To summarize (and borrow from @EricLaw's comment):
- 没有UA字符串中的三叉戟 - 检查
MSIE [0-9] .0
字符串版本 - Trident / 4.0 - IE 8,版本
MSIE
不相关 - Trident / 5.0 - IE 9
- no Trident in UA string - check the
MSIE [0-9].0
string for version - Trident/4.0 - IE 8, version in
MSIE
is not relevant - Trident/5.0 - IE 9
这篇关于检测IE版本不考虑兼容模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!