Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketaylr/374385 to your computer and use it in GitHub Desktop.
Save miketaylr/374385 to your computer and use it in GitHub Desktop.
//detect Internet Explorer and version number through injected conditional comments (no UA detect, no need for cond. compilation / jscript check)
//version arg is for IE version (optional)
//comparison arg supports 'lte', 'gte', etc (optional)
var isIE = (function(undefined){
var doc = document,
doc_elem = doc.documentElement,
cache = {},
elem;
return function( version, comparison ) {
if(/*@cc_on!@*/true){return false;}
var key = [ comparison || '', 'IE', version || '' ].join(' ');
if ( cache[ key ] === undefined ) {
elem = elem || doc.createElement( 'B' );
elem.innerHTML = '<!--[if '+ key +']><b></b><![endif]-->';
cache[ key ] = !!elem.getElementsByTagName( 'b' ).length;
}
return cache[ key ];
};
})();
//minified:
var isIE=(function(){var doc=document,doc_elem=doc.documentElement,cache={},elem;return function(version,comparison){if(/*@cc_on!@*/true){return false;}var key=[comparison||"","IE",version||""].join(" ");if(cache[key]===undefined){elem=elem||doc.createElement("B");elem.innerHTML="<!--[if "+key+"]><b></b><![endif]-->";cache[key]=!!elem.getElementsByTagName("b").length;}return cache[key];};})();
//is it IE?
isIE();
//is it IE6?
isIE(6);
//is it less than or equal to IE 7?
isIE(7,'lte');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment