Skip to content

Instantly share code, notes, and snippets.

@Tatsh
Created December 13, 2011 18:12
Show Gist options
  • Save Tatsh/1473175 to your computer and use it in GitHub Desktop.
Save Tatsh/1473175 to your computer and use it in GitHub Desktop.
Detect IE using conditional comments
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