Created
September 22, 2011 16:09
-
-
Save apapirovski/1235185 to your computer and use it in GitHub Desktop.
Test for IE in JS using Conditional Comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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