0

I have to check when a user has selected Quirks or Standard document mode from the developer tool for IE10. Using the below code, i always get the same value i.e. 10 for both the modes.

document.documentMode

Please let me know how could i discriminate between the two document modes in IE10. I am using javascript for the same.

Rosane
  • 21
  • 3
  • What do you need this for? If your page has a valid doctype it should never go into quirks mode unless the user goes to the dev tools and manually changes it. Frankly, if he does that, he deserves everything he gets. – Spudley Dec 03 '13 at 14:02
  • possible duplicate of [JavaScript: Can I detect IE9 if it's in IE7 or IE8 compatibility mode?](http://stackoverflow.com/questions/5825385/javascript-can-i-detect-ie9-if-its-in-ie7-or-ie8-compatibility-mode) – Mark Dec 03 '13 at 15:48
  • This issue is arising only for IE10 and @Spudley you are right. In this scenario user is only changing the document mode but our site displays properly for Standards Mode but distorts for Quirks mode. For this we are planning to display an error message. Since the "document.documentMode" is giving me the same value i.e. 10 for both the modes, i am not able to discriminate between them. Any pointers in this regards will be appreciated. – Rosane Dec 04 '13 at 04:59

1 Answers1

0

I used the below code and every thing worked fine. This is working on all the IE versions (Tested and Verified :) ).

//Checks the document mode of the IE and displays an error if the doc mode is not supported
function CheckDocMode() {

//Get the browser name
var browserName = navigator.appName;

//Do not display the Div containing the error message
document.getElementById('DocModeError').style.display = 'none';

//Check if the browser is IE
if (browserName == "Microsoft Internet Explorer") {

    //Get the IE version, document mode and complatibility mode
    var IEVersion = GetIEVersion();
    var IEDocMode = document.documentMode;
    var IECompatibilityMode = document.compatMode;

    //Confirm that the browser is IE8/9/10
    if (IEDocMode != undefined) {

        //Do not display the error message if the IE=10 and Doc Mode = Standard
        if ((IEVersion == 10 || IEVersion == 9 || IEVersion == 8 || IEVersion == 7)
            && (IEDocMode == 10 && IECompatibilityMode == "CSS1Compat")) {
            return;
        }

        //Display the error if the document mode is anything other than IE8 and IE9
        if (IEDocMode != 8 && IEDocMode != 9) {
            document.getElementById('DocModeError').style.display = 'block';
        }
    }
}
}

function GetIEVersion() {
    var myNav = navigator.userAgent.toLowerCase();
    return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
}
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Rosane
  • 21
  • 3