嘿, 我是Mofei!
Distinguishing Between IE6, IE7, and IE8 in JavaScript
Published November 10, 2012 at 08:13 PM

It is often necessary to distinguish between different browsers, so here are a few methods to differentiate various versions of IE. First, to identify an IE browser, we primarily use the ActiveXObject, which is a unique object of IE, to determine if it is an IE browser. Based on this, we can use XMLHttpRequest to check for IE6, and documentMode to identify IE8. As for IE7, there is no specific method provided; of course, considering that IE10 has already been released, the issues to consider are not so simple. I will update on distinguishing IE10 after I get to test it.

var isIE=!!window.ActiveXObject;
var isIE6=isIE&&!window.XMLHttpRequest;
var isIE8=isIE&&!!document.documentMode;
var isIE7=isIE&&!isIE6&&!isIE8;
if (isIE){
    if (isIE6){
        alert(”ie6″);
    }else if (isIE8){
        alert(”ie8″);
    }else if (isIE7){
        alert(”ie7″);
    }
}
THE END
Previous
Seamless Refresh with onhashchange and AJAX
Next
Internet Explorer 10 Compatibility White Paper (Part 1)

More Great Articles

Your comment might help others too—feel free to share your thoughts!

avatar

Mofei's Friend (Click to edit)

Write something, I won't judge.
No comments yet
Be the first to comment!

HI. I AM MOFEI!

NICE TO MEET YOU!