0

我需要一个JavaScript代码“document.documentMode”,它在真正的IE8模式下的值为8,在IE7模式下的值为7。IE8兼容模式 - document.documentMode

用户代理字符串在两种情况下都是相同的,并且仍然会声明IE8。请注意,此JavaScript变量仅在IE8中可用。

基本上,我必须检测何时有人正在运行IE8(tue)和IE8(在兼容模式下)。

+0

你检查[这](http://stackoverflow.com/questions/1208837/how-can-i-detect-if-ie8-is-running-in-compatibility-view) – Mohayemin 2012-08-10 09:16:32

+0

我做现在。谢谢。有什么代码可以推荐给我?> – DD77 2012-08-10 09:25:31

+0

嗯,我不是你感兴趣的话题的专家。刚刚搜索你的要求,发现后,并认为它可能会有所帮助:) – Mohayemin 2012-08-10 09:33:32

回答

2

“基本上,我必须检测到有人在运行IE8(tue)和IE8(在兼容模式下)。”

var ie8 = /msie\s+8/i.test(navigator.userAgent); 
var mod = document.documentMode; 
if (ie8 && mod == 8) { 
    alert("found!"); 
} 

// or 
var ok = (
    /msie\s+8/i.test(navigator.userAgent) && 
    document.documentMode == 8 
); 
if (ok) { 
    // ...