0

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).

Cincinnati Joe
  • 2,077
  • 6
  • 23
  • 32
  • Honestly I'm not sure there *is* a way. The whole point of compatibility mode is that they're indistinguishable. – Anthony Grist Feb 05 '14 at 16:20
  • You're probably better off forcing the browser into it's "native" behavior with the X-UA-Compatible `` or header (preferably). If your page works with newer browsers, just override the browser setting. – Pointy Feb 05 '14 at 16:21
  • In IE there's `ScriptEngine` function available, please see [this answer](http://stackoverflow.com/a/19570684/1169519). – Teemu Feb 05 '14 at 16:24
  • 1
    Sounds like the "Trident" value in the agent string may be able to be used. So for IE8, check for "Trident/4.0" rather than "Trident/5.0" for IE9, etc. Haven't verified this yet. Details: [MSDN: Understanding user-agent strings](http://msdn.microsoft.com/library/ms537503.aspx#TriToken) – Cincinnati Joe Feb 05 '14 at 16:34

1 Answers1

0

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
Cincinnati Joe
  • 2,077
  • 6
  • 23
  • 32