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
- that browser is IE7
- that browser is in IE7 compatibility mode
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.userAgenthas the substringTridentin it. An IE8+ always has aTridentin 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
Tridentis 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-Agentheader might not always matchnavigator.userAgent. This is the case at least with IE9 that has compatiblity mode on (sends an IE7User-Agentheader) but detects something likeIE=Edgein the response (navigator.userAgentturns back to IE9).