does anyone know how to check if IE 11 compatibility mode is ON when I'm on a website through javascript?
I added the url to the list compatibility view settings. But when I do
navigator.userAgent
in developer tools, it returns
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; InfoPath.3; rv:11.0) like Gecko
Looking at the microsoft website (http://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx), it says
The compatible ("compatible") and browser ("MSIE") tokens have been removed.
Any help on detecting whether a page is using compatibility view via javascript would be really helpful. Thanks in advance.
SOLVED
While searching for an answer to this question myself, I found this solution from Nenad Bulatovic in another thread but his response wasn't marked as the correct answer. I tested this out in IE11 and downgrading to IE5 and found that it works for IE7-IE11, which is great. I wanted to share it here in case anyone else finds it useful.
iecheck.js
iecheck.html
source: Detect IE10 compatibility mode
Add this to web.config file and application will overwrite user's setting.
Place the "system.webServer" tag at the end of your web.config file just before the closing "configuration" tag. Additionally, you can add the X-UA-Compatible tag in IIS on your webserver by selecting your website and clicking on the HTTP Response Headers icon.
A reliable solution you can edit that works for Internet Explorer 8 to 11 (needs extra code to support < IE8).
Nasty side-effects (only if IE < 11 or documentMode < 11 -- ouch):
//@ sourceMappingURL=xx.js
(e.g. in jQuery < 1.11, or other libraries that haven't updated to the newer//#
format).The basic reason it works is that:
returns the real version of IE regardless of compatibility mode. Notes:
I wrote a JavaScript function, ie-truth, to do just this. How it works is that in IE 11 if compatibility mode is turned on, the User Agent string will contain the Trident version number for IE 11 (7.0) as well as the MSIE version number for an older version of IE (such as 7.0 for IE 7). This also applies to compatibility mode in older versions of IE.
I would recommend that one uses feature detection rather than indirectly querying the browser version. So, for example, if you require the HTML 5 history API feature, do something like:
A simple solution, try it in the console:
Will detect any IE less than IE9 (including compatibility view). Would also detect Chrome 4-14 according to caniuse.
IE 6-8: Supports selection events, but not window.getSelection() Ref: https://caniuse.com/#feat=selection-api