Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect IE10 compatibility mode

I have some specific code paths for IE 10 and rest of the IE versions. If IE10 is running in compatibility mode, browser version is set to 7.0. Is there a way to detect if it is IE 10 irrespective of the standard/compatibility mode using JavaScript/JQuery?

like image 320
ABC Avatar asked Feb 09 '13 21:02

ABC


People also ask

How do I know if IE 11 is in compatibility mode?

In Internet Explorer 11, you can see if Compatibility Mode is set by clicking on the gear in the upper right-hand corner of the browser and selecting "Compatibility View settings". In the window that pops up, you can see if Compatibility Mode is turned on by seeing if "Use Microsoft compatibility lists" is checked.

Is IE10 still supported?

After January 14, 2020, IE 10 will not release any security or non-security updates, free or paid assisted support options, or online technical content changes for IE 10. Customers will have until January 31, 2020, to complete the transition from IE 10 to IE 11 to remain supported.


2 Answers

You can detect this using the navigator.userAgent string, for example

"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; InfoPath.3; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Zune 4.7)"

Trident/6.0 means IE10

MSIE 7.0 means compatibility mode

More details: https://stackoverflow.com/a/5825518/255654

like image 96
Sergei Grebnov Avatar answered Sep 30 '22 16:09

Sergei Grebnov


This should work detect compatibility mode for MSIE.

iecheck.js

function trueOrFalse() {
    return true;
}

function IeVersion() {
    //Set defaults
    var value = {
        IsIE: false,
        TrueVersion: 0,
        ActingVersion: 0,
        CompatibilityMode: false
    };

    //Try to find the Trident version number
    var trident = navigator.userAgent.match(/Trident\/(\d+)/);
    if (trident) {
        value.IsIE = true;
        //Convert from the Trident version number to the IE version number
        value.TrueVersion = parseInt(trident[1], 10) + 4;
    }

    //Try to find the MSIE number
    var msie = navigator.userAgent.match(/MSIE (\d+)/);
    if (msie) {
        value.IsIE = true;
        //Find the IE version number from the user agent string
        value.ActingVersion = parseInt(msie[1]);
    } else {
        //Must be IE 11 in "edge" mode
        value.ActingVersion = value.TrueVersion;
    }

    //If we have both a Trident and MSIE version number, see if they're different
    if (value.IsIE && value.TrueVersion > 0 && value.ActingVersion > 0) {
        //In compatibility mode if the trident number doesn't match up with the MSIE number
        value.CompatibilityMode = value.TrueVersion != value.ActingVersion;
    }
    return value;
}

iecheck.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Testing IE Compatibility Mode</title>
    <script src="iecheck.js" type="text/javascript"></script>
</head>
<body>
<div id="results">Results: </div>
</br>
<script type="text/javascript">

var ie = IeVersion();

document.write("IsIE: " + ie.IsIE + "</br>");
document.write("TrueVersion: " + ie.TrueVersion + "</br>");
document.write("ActingVersion: " + ie.ActingVersion + "</br>");
document.write("CompatibilityMode: " + ie.CompatibilityMode + "</br>");

</script>
</body>
</html>
like image 33
Nenad Bulatović Avatar answered Sep 30 '22 18:09

Nenad Bulatović