Detecting IE7+ in javascript

Thursday, October 26th, 2006 @ 11:38 am | filed under: Browser Stuff

via ajaxian:

Abe Fettig knows that we need to start detecting the difference between IE6- and IE7+, because a lot of the hacks that we were using for IE are no longer needed.

He didn’t want to grok the user agent, as that is very brittle, so he came up with:

if (typeof document.body.style.maxHeight != “undefined”) {
// IE 7, mozilla, safari, opera 9
} else {
// IE6, older browsers
}

Any other thoughts?


Indeed there are many thoughts on the subject; the post illicited over 20 comments with other solutions:

You can also use the XHR check:

if (window.XMLHttpRequest) {
   // IE 7, mozilla, safari, opera 9
} else {
   // IE6, older browsers
}

Yeah, how about using Conditional Compilation of JavaScript in IE

Conditional comments could also be used. eg.


isIE7 = true;

.. Or something along those lines. See @MSDN.

> More

No TweetBacks yet. (Be the first to Tweet this post)

Comments are closed.