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!
Written by Roll
Related protips
2 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Html
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#