Hi, I am Mofei!
...

How to Detect IE6, IE7, and IE8 Using JavaScript

Quickly identify IE6, IE7, and IE8 browser versions using simple JavaScript code.

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″);
    }
}

Have questions or a different perspective? Let’s discuss in the comments!

How to Detect IE6, IE7, and IE8 Using JavaScript | Hi, I am Mofei!