Skip to content

Instantly share code, notes, and snippets.

@jamenlyndon
Last active August 29, 2015 14:25
Show Gist options
  • Save jamenlyndon/04c8ea13b9bdaecd4b41 to your computer and use it in GitHub Desktop.
Save jamenlyndon/04c8ea13b9bdaecd4b41 to your computer and use it in GitHub Desktop.
Check for IE (JS)
// Check for IE
// ------------------------------------------------
var ie = (function(){
var undef;
var v = 3;
var div = document.createElement('div');
var all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : undef;
}());
// Example usage
// ------------------------------------------------
if (ie) {
console.log("Rats, they're using IE");
} else if (!ie) {
console.log("Hooray, it's not IE!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment