Created
November 22, 2010 16:48
-
-
Save getify/710231 to your computer and use it in GitHub Desktop.
how to detect IE from JavaScript 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
// stripped down version just detecting IE | |
(function(global){ | |
global._isIE = false; | |
try { | |
var div = document.createElement("div"); | |
div.innerHTML = "<!--[if IE]><i></i><![endif]-->"; | |
global._isIE = (div.getElementsByTagName("i").length > 0); | |
} catch(err) { } | |
})(window); |
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
// fuller version with version detection (in this case, IE6) | |
(function(global){ | |
global._isIE = false; | |
global._isIE6 = false; | |
try { | |
var div = document.createElement("div"), | |
all = div.getElementsByTagName("i") | |
; | |
div.innerHTML = "<!--[if IE]><i></i><![endif]--><!--[if IE 6]><i></i><![endif]-->"; | |
if (all[0]) global._isIE = true; | |
if (all[1]) global._isIE6 = true; | |
} catch(err) { } | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI: the "original" gist (from james padolsey) with a more capable version of this technique for any IE versions, etc: https://gist.github.com/527683