Skip to content

Instantly share code, notes, and snippets.

@apapirovski
Created September 22, 2011 16:09
Show Gist options
  • Save apapirovski/1235185 to your computer and use it in GitHub Desktop.
Save apapirovski/1235185 to your computer and use it in GitHub Desktop.
Test for IE in JS using Conditional Comments
// Based on jamespadolsey's gist: https://gist.github.com/527683
// -----------------------------------------------------------------
// Was curious to see what method would yield the best 'performance'
// — turns out that using innerHTML and checking for text is
// marginally faster than using a Live NodeList.
//
// Of course, any performance gains can only be seen at 100+
// iterations, but still somewhat interesting.
(function (ie) {
window[ie] = (function() {
var ie = 3,
p = document.createElement('p'),
undefined;
do {
ie += 1;
p.innerHTML = '<!--[if gt IE ' + ie + ']>IE<![endif]-->';
} while (p.innerHTML === 'IE');
return ie > 4 ? ie : undefined;
}());
}('ieDetect'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment