Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get browser "Document Mode"

I am developing some kind of JavaScript library. And i cause the problem that i have some specific issues for: Browser : IE8 / IE9 and Document Mode : IE7 I found the solution, but i don't want to use it in all situation, and want to use it just when i have the situation described above. I know that I can recognize browser by using:

return navigator.userAgent.toLowerCase().indexOf('MSIE 8') > -1;

But i recognize just browser version in such way but not the document mode, and i don't want to use my solution when I have, for example, browser mode IE8 and document mode IE 8. Is there a way to get page document mode in IE? Thanks in advance.

like image 548
Mikhail Avatar asked Oct 29 '12 11:10

Mikhail


1 Answers

You can use document.documentMode to return exactly what document mode IE is using.

Meaning that if you have your browser mode set to IE9, but your document mode to IE8 it will return document.documentMode == 8 (while the userAgent string will still show up as IE9). This is particularly useful if your JS ever includes styling changes as it is the document mode that determines how IE renders a page, not the browser mode. Compatibility mode really just changes the document mode (usually to IE7).

In the few cases I've needed to I've just used something like this to differentiate IE's:

if (document.documentMode == 7) {
    doSomethingIn.IE7_only;
} else {
    doSomething.everwhereElse;
}

Hope that helps some.

like image 63
Sam Thornton Avatar answered Oct 08 '22 01:10

Sam Thornton