esedic
12/28/2015 - 12:18 PM

Detect IE with JavaScript

Detect IE with JavaScript

var IEversion = detectIE();
if (IEversion !== false) {
    document.getElementById('result').innerHTML = 'IE ' + IEversion;
} else {
    document.getElementById('result').innerHTML = 'NOT IE';
}
document.getElementById('details').innerHTML = window.navigator.userAgent;

function detectIE() {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf('MSIE ');
    if (msie > 0) {
        return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
    }
    var trident = ua.indexOf('Trident/');
    if (trident > 0) {
        var rv = ua.indexOf('rv:');
        return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
    }
    var edge = ua.indexOf('Edge/');
    if (edge > 0) {
        return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
    }
    return false;
}