Browser Detection, Detecting IE7 via Object Detection

Object detection is a really simple and intuitive way to detect certain kinds of browsers if the Object you try to access is 99% proprietary for those browser especially when those Objects are a part of web standard.

For example, window.opera is one of the simplest and fastest ways to detect whether the browser is Opera since the following rules are 99% true to me.

  1. No browsers will implement window.opera except Opera itself.
  2. I don't see the possibility of the the implementation of window.opera as a web standard Object of browsers.
  3. window.opera seems to be an white element property to me, which is somehow very good in the perspective of Object Detection for Browser Detection.

On the other hand, some of the none-standard DOM/BOM Objects / Methods are getting popular and they're no longer proprietary to one browser.

For example, you can collect more than one browsers by doing this:

  1. var isBrowserCompatible = !!(document.createElement('canvas').getContext) ); //Firefox, Opera, Safari
  2. var isBrowserCompatible = !!(window.XMLHttpRequest) ); //Firefox, Opera, Safari, IE7

Though both CANVAS and XMLHttpRequest are not web standard at this moment, but their usefulness will make more vendors to implement this feature, which means that they can't be the white element features for developers and browsers and we should avoid using these methods to detect browsers.

Therefore, you may imagine that this won't be a good practice of Object Detection for Browser Detection:

  1. var isBrowserCompatible = !!(window.JSONRequest ); //Firefox 12, Opera 23, Safari 5.5 and IE9?

As long as a feature such as JSONRequest is useful in general and it benefit developers and users now or maybe in the future across browsers, we should avoid using it for Object Detection. Even though the browser does not have the Object natively, someone else might implement it anyway.

Back to the title of this article, the question is how do I detect IE7 via Object Detection?

Based on these principles I just talked about:

I' ssuggest that we can detect IE7( or greater version) by doing this:


        var ie7=!!(
                    (ie7 = document.documentElement.currentStyle) && 
                    (typeof(ie7['msInterpolationMode'])!='undefined')
                  );

This one line script uses msInterpolationMode to check whether the client is IE7 o browser, and it's really simple.

Cheers, a little bit. :-)

Hedger Wang