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) { 
    // ...