嘿, 我是Mofei!
32,872
How to Detect IE6, IE7, and IE8 Using JavaScript
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

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

Mofei's Friend

avatar
What's on your mind today?
No comments yet
Be the first to comment!

HI. I AM MOFEI!

NICE TO MEET YOU!