问题描述:

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? Note that I'm not looking for feature availability, but want to give a message specific to 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. 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.

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. 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. Below are the values for different versions of IE. So for IE8, checking for "Trident/4.0" seems to work. 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
相关阅读:
Top