none
How to Detect compatibility mode in IE (any version)

    Question

  • How to Detect Is IE running in  compatibility mode (any version)

    or Force fully set  IE in  compatible mode


    • Edited by CuriousPoo Friday, December 09, 2011 9:54 AM
    Friday, December 09, 2011 7:56 AM

Answers

  • Hi CuriousPoo,

    There is no ready-made way to detect this. We can proceed with the othernesses of the value to the navigator.userAgent property under different browse mode:
    http://msdn.microsoft.com/en-us/library/cc197025(v=vs.85).aspx.
    We can get familiar with this property and the Compatibility View mode of IE8 and IE9 via the following two blogs:
    Introducing Compatibility View: http://blogs.msdn.com/b/ie/archive/2008/08/27/introducing-compatibility-view.aspx.
    Introducing IE9's User Agent String: http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx.

    After research, we can find that the values to the User Agent String under different browse modes are:
    IE7: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1;...)
    IE8: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0;...)
    IE8 Compatibility View: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0;...)
    IE9: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
    IE9 Compatibility View: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0;...)

    Note that some irrelevant values in the strings are ignored, we only need to focus on some critical values which can be combined to decide the browse mode, like MSIE version NO. and Trident Mode NO..

    Here comes the final solution:
            var agentStr = navigator.userAgent;
            var mode;
            if (agentStr.indexOf("Trident/5.0") > -1) {
                if (agentStr.indexOf("MSIE 7.0") > -1)
                    mode = "IE9 Compatibility View";
                else
                    mode = "IE9";
            }
            else if (agentStr.indexOf("Trident/4.0") > -1) {
                if (agentStr.indexOf("MSIE 7.0") > -1)
                    mode = "IE8 Compatibility View";
                else
                    mode = "IE8";
            }
            else
                mode = "IE7";
    
            document.title = "Browser Mode:\t" + mode;
            //document.write(navigator.userAgent);

    Have a nice day,
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 13, 2011 12:17 PM

All replies

  • Hi CuriousPoo,

    There is no ready-made way to detect this. We can proceed with the othernesses of the value to the navigator.userAgent property under different browse mode:
    http://msdn.microsoft.com/en-us/library/cc197025(v=vs.85).aspx.
    We can get familiar with this property and the Compatibility View mode of IE8 and IE9 via the following two blogs:
    Introducing Compatibility View: http://blogs.msdn.com/b/ie/archive/2008/08/27/introducing-compatibility-view.aspx.
    Introducing IE9's User Agent String: http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx.

    After research, we can find that the values to the User Agent String under different browse modes are:
    IE7: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1;...)
    IE8: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0;...)
    IE8 Compatibility View: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0;...)
    IE9: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
    IE9 Compatibility View: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0;...)

    Note that some irrelevant values in the strings are ignored, we only need to focus on some critical values which can be combined to decide the browse mode, like MSIE version NO. and Trident Mode NO..

    Here comes the final solution:
            var agentStr = navigator.userAgent;
            var mode;
            if (agentStr.indexOf("Trident/5.0") > -1) {
                if (agentStr.indexOf("MSIE 7.0") > -1)
                    mode = "IE9 Compatibility View";
                else
                    mode = "IE9";
            }
            else if (agentStr.indexOf("Trident/4.0") > -1) {
                if (agentStr.indexOf("MSIE 7.0") > -1)
                    mode = "IE8 Compatibility View";
                else
                    mode = "IE8";
            }
            else
                mode = "IE7";
    
            document.title = "Browser Mode:\t" + mode;
            //document.write(navigator.userAgent);

    Have a nice day,
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 13, 2011 12:17 PM
  • Included IE 10, ensured properties are not set for non-IE browsers, updated as a JS object.  Example call from JQuery .ready ...

      $(document).ready(function () {
        var iec = new IECompatibility();
        alert('IsIE: ' + iec.IsIE + '\nVersion: ' + iec.Version + '\nCompatability On: ' + iec.IsOn);
      });
    
      function IECompatibility() {
        var agentStr = navigator.userAgent;
        this.IsIE = false;
        this.IsOn = undefined;  //defined only if IE
        this.Version = undefined;
    
        if (agentStr.indexOf("MSIE 7.0") > -1) {
          this.IsIE = true;
          this.IsOn = true;
          if (agentStr.indexOf("Trident/6.0") > -1) {
            this.Version = 'IE10';
          } else if (agentStr.indexOf("Trident/5.0") > -1) {
            this.Version = 'IE9';
          } else if (agentStr.indexOf("Trident/4.0") > -1) {
            this.Version = 'IE8';
          } else {
            this.IsOn = false; // compatability mimics 7, thus not on
            this.Version = 'IE7';
          }
        } //IE 7
      }



    • Edited by SySys Thursday, August 29, 2013 9:27 PM
    Thursday, August 29, 2013 8:11 PM