Can I differentiate if client's browser is IE7 or e.g. IE9 in IE7 compatibility mode? I'm trying to figure out if I can do a JS check on my site which would recognize two different things and do different stuff depending on the result
I have the first condition working correctly as it's pretty much said everywhere how to do it. Not sure about the second one and/or combination of both.
For at least IE8 and IE9, you can check whether navigator.userAgent
has the substring Trident
in it. An IE8+ always has a Trident
in its user-agent, where an IE7 doesn't. See this answer and the MSDN link in it.
IE10 seems trickier: it is reported in the comments below that Trident
is not always present with IE7 emulation mode. Probably the OS string (eg. Windows NT 6.2
) will still reveal IE10, if IE10 will not be available on any platform where IE7 is available.
Please also note that the HTTP User-Agent
header might not always match navigator.userAgent
. This is the case at least with IE9 that has compatiblity mode on (sends an IE7 User-Agent
header) but detects something like IE=Edge
in the response (navigator.userAgent
turns back to IE9).