繁体   English   中英

如何区分IE10的标准和怪癖文档模式

[英]how to differentiate between standard and quirks document mode for IE10

我必须检查用户何时从IE10的开发人员工具中选择了怪癖或标准文档模式。 使用下面的代码,我总是得到相同的值,即两种模式都为10。

document.documentMode

请让我知道如何在IE10中区分两个文档模式。 我使用javascript相同。

我使用下面的代码,一切正常。 这适用于所有IE版本(已测试和已验证:))。

//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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM