document.documentMode
。有效值为5、7(兼容模式)、8、9、10和11(Edge)。
在控制台中设置兼容模式会直接更改该值。
加载包含<meta http-equiv
标签的页面会更改该值。
将网站添加到"工具->兼容性视图设置"中的兼容性模式会将该值更改为7。
https://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx
示例
例如,如果我在IE11中加载此页面,则会获得documentMode
为11。
<!doctype HTML>
<body>
<p>Hello World!<p>
</body>
此页面在IE11中加载时将documentMode
设置为9。
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=9"/>
</head>
<body>
<p>Hello World!<p>
</body>
</html>
var ieUserAgent = {
init: function () {
// Get the user agent string
var ua = navigator.userAgent;
this.compatibilityMode = false;
// alert (ua);
if(ua.indexOf("MSIE") == -1){
this.version = 0;
return 0;
}
if(ua.indexOf("compatible") == -1){
this.compatibilityMode = false;
return 0;
}else{
this.compatibilityMode = true;
return 0;
}
}
};
// Initialize the ieUserAgent object
ieUserAgent.init();
-OR-
/** * 检查客户端是否为IE并处于兼容性视图 * * @returns {boolean} */
function isIECompatibilityMode() {
var ua = navigator.userAgent;
if (ua.indexOf("MSIE") == -1) {
return false;
}
return (ua.indexOf("compatible") != -1); }
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
...在兼容性视图下是Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0;)
(为了清晰起见,已删除.NET部分)——关于IE11:版本:11.674.15063.0
,更新版本:11.0.47
。 - Jaromanda X