简体   繁体   English

设置IE8兼容性时如何检测IE8与较新版本的区别

[英]How to detect IE8 separate from newer versions when IE8 compatibility set

An odd question: Given that a site forces IE8 compatibility with a statement like the following, how can code in the browser detect whether the browser is actually IE8 and not some newer version? 一个奇怪的问题:考虑到网站强制IE8与以下语句兼容,浏览器中的代码如何才能检测到浏览器实际上是IE8,而不是较新的版本? Note that I'm not looking for feature availability, but want to give a message specific to IE8. 请注意,我并不是在寻找功能的可用性,而是要提供特定于IE8的消息。

<meta content='IE=8' http-equiv='X-UA-Compatible' />

There are lots of ways documented for detecting IE8 but they only seem to work compared to older versions. 记录了很多检测IE8的方法,但与旧版本相比,它们似乎只能工作。 Newer versions like IE11 seem to do such a good job at behaving like IE8 when in compatibility mode that the js and css approaches of detecting IE8 can't see to tell them apart. 在兼容模式下,像IE11之类的较新版本在表现如IE8方面似乎表现出色,以至于检测IE8的js和css方法都看不出来。

I've tried various approaches listed on StackOverflow and various other sites, but none seem to be able to detect IE8 from IE11 when the site has forced them into IE8 compatibility mode. 我已经尝试了StackOverflow和其他各个站点上列出的各种方法,但是当该站点将它们强制为IE8兼容模式时,似乎都无法从IE11中检测到IE8。 Please only answer with ways that definitely work for this exact case (not just suggestions of what might work - I've tried many of those). 请仅使用肯定适用于此确切情况的方式进行回答(而不仅仅是对可能有效的建议-我已经尝试了许多方法)。

Reading a particular MSDN doc indicates that the "Trident" value in the agent string can be used regardless of compatibility setting. 读取特定的MSDN文档会表明,无论兼容性设置如何,都可以使用代理字符串中的“ Trident”值。 Below are the values for different versions of IE. 下面是不同版本的IE的值。 So for IE8, checking for "Trident/4.0" seems to work. 因此,对于IE8,检查“ Trident / 4.0”似乎可行。 Details: Understanding user-agent strings 详细信息: 了解用户代理字符串

Token         Description
Trident/7.0   IE11
Trident/6.0   Internet Explorer 10
Trident/5.0   Internet Explorer 9
Trident/4.0   Internet Explorer 8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM