documentMode(For IE)属性
从IE8开始,IE为JS新增了一个文档兼容性模式属性documentMode。
浏览器 | document.documentMode值 |
IE6 | undefined |
IE7 | undefined |
IE8 | 8 |
IE8兼容模式 | 7 |
IE9 | 9 |
IE9兼容模式 | 7|8 |
IE10 | 10 |
IE10兼容模式 | 7|8|9 |
在IE的怪异模式(quirks mode)下,documnet.documentMode的值是5,这个与document.compatMode属性有关;当文档还没有完成加载时,document.documentMode的值为0。
通过document.documentMode,可以用以下方法判断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; var isIE10 = isIE && ieMode==10;