-1

I need a javascript code "document.documentMode" which will have a value of 8 in true IE8 mode and 7 in IE7 mode.

The user agent string will be identical in both cases and will still state IE8. Note that this JavaScript variable is only available in IE8.

Basically, I must detect when someone is running IE8 (tue) and IE8 (in compatibility mode).

Cœur
  • 37,241
  • 25
  • 195
  • 267
DD77
  • 1,367
  • 2
  • 13
  • 25
  • Did you check [this](http://stackoverflow.com/questions/1208837/how-can-i-detect-if-ie8-is-running-in-compatibility-view) – Mohayemin Aug 10 '12 at 09:16
  • I did now. thanks. there's any code that you can recommend me?> – DD77 Aug 10 '12 at 09:25
  • Well, I am not an expert of the topic you are interested about. Just searched your requirement and found that post and thought it might be helpful :) – Mohayemin Aug 10 '12 at 09:33
  • Dumb question: Why do you need to know/do this? Normally the page author (you) decide if a page runs in standards or compatibility mode. It's rare that the user needs or needs to switch, and if they do it's their own fault. – RoToRa Aug 10 '12 at 11:04

1 Answers1

2

"Basically, I must detect when someone is running IE8 (tue) and IE8 (in compatibility mode)."

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) {
    // ...
Kerem
  • 11,377
  • 5
  • 59
  • 58