首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何区分IE10的标准文档模式和古怪文档模式

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

Stack Overflow用户
提问于 2013-12-03 13:39:41
回答 1查看 407关注 0票数 0

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

代码语言:javascript
复制
document.documentMode

请告诉我如何在IE10中区分这两种文档模式。我同样使用javascript。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-14 14:25:46

我使用了下面的代码,每件事都很好。这适用于所有IE版本(经过测试和验证:)。

代码语言:javascript
复制
//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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20352705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档