Created
December 13, 2011 18:12
-
-
Save Tatsh/1473175 to your computer and use it in GitHub Desktop.
Detect IE 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
var isIEStatic = null; | |
var isIE = function () { | |
if (isIEStatic === null) { | |
var div = document.createElement('div'); | |
div.style.display = 'none'; | |
div.innerHTML = '<!--[if IE]><div id="ie-find"><[endif]-->'; | |
document.body.appendChild(div); | |
if (document.getElementById('ie-find')) { | |
isIEStatic = true; | |
} | |
else { | |
isIEStatic = false; | |
} | |
document.body.removeChild(div); | |
} | |
return isIEStatic; | |
}; | |
var isIEVersionStatics = {}; | |
var isIEVersion = function (version) { | |
if (!isIEVersionStatics[version]) { | |
var div = document.createElement('div'); | |
div.style.display = 'none'; | |
div.innerHTML = '<!--[if IE ' + version + ']><div id="ie-find"><[endif]-->'; | |
document.body.appendChild(div); | |
if (document.getElementById('ie-find')) { | |
isIEVersionStatics[version] = true; | |
} | |
else { | |
isIEVersionStatics[version] = false; | |
} | |
document.body.removeChild(div); | |
} | |
return isIEVersionStatics[version]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment