Last Updated: February 25, 2016
·
1.161K
· rollroll

Javascript - get IE version

You can get IE version of this function
( p.s. IE 10 doesn't support conditional comments )

/**
 * Get the major version of IE
 * @params [ [integer] ]
 * @return [integer || boolean]
 * @reference James Padolsey <https://gist.github.com/527683>
 */
isIE: function( version ) {
    var 
        self = this.isIE,
        ieVersion = self.version;

    ieVersion = self.version = ( ieVersion !== undefined )? ieVersion
        : (function(){
            var 
                v = 3, div, all,
                isIE10 = ( eval("/*@cc_on!@*/false") && document.documentMode === 10 );

            if ( isIE10 ) return 10;

            div = document.createElement('div'),
            all = div.getElementsByTagName('i');

            while (
                div.innerHTML = '<!--[if gt IE ' + ( ++v ) + ']><i></i><![endif]-->',
                all[0]
            ){;}

            return ( v > 4 )? v : false;
        }());

    return ( version )? version === ieVersion : ieVersion;
}

Examples

var ieVersion = isIE();
var isIE =  !! isIE();
var isIE6 =  isIE( 6 );
var isIE8 =  isIE( 8 );
var isIE10 =  isIE( 10 );

P.S. Thank you galulex!

2 Responses
Add your response

I think function call with parameter is better isIE(8) than isIE() === 8

over 1 year ago ·

it's really a good idea! thank you galulex!

over 1 year ago ·