技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> JavaScript --> IE的documentMode属性

IE的documentMode属性

浏览:1715次  出处信息

IE8+新增了一个获取的文档兼容性模式属性——documentMode。一般的获取文档兼容模式可以这么写:

var p= document.documentMode;


在各浏览器下值见下表:

浏览器IE6IE7IE8IE8 兼容模式IE9IE9 兼容模式IE10IE10 兼容模式
document.documentModeundefinedundefined8797||8107||8||9

除了这些取值,在IE的怪异模式下,document.documentMode的值是5;这个和document.compatMode属性有关,在html文档中没有指定DOCTYPE,在ie下就是怪异模式。

送一个document.compatMode属性,如果是标准模式,则document.compatMode的值等于”CSS1Compat“,如果是怪异模式,则document.compatMode的值等于”BackCompat“

if (document.compatMode == "CSS1Compat") {
    alert("Standards mode");
} else {
    alert("Quirks mode");
}

如果文档正在加载中,尚未完成加载,那么document.documentMode的值是0,所以你要确保文档加载完成才能取到正确的值。
开发人员会使用meta元素来指定X- UA-兼容的HTTP- EQUIV头的指定文档兼容性模式。

另:有了这个属性,判断ie各种版本也有了新方法,比较靠谱:

var ieMode=document.documentMode;
var isIE=!!window.ActiveXObject;
var isIE6=isIE&&!window.XMLHttpRequest;
var isIE7=isIE&&!isIE6&&!ieMode||ieMode==7;
var isIE8=isIE&&ieMode==8;
var isIE9=isIE&&ieMode==9;


test页面:http://www.css88.com/demo/ie_documentMode/

详细信息:http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx


QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1