Skip to content

Instantly share code, notes, and snippets.

@julianshapiro
Last active August 2, 2017 01:02
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save julianshapiro/9098609 to your computer and use it in GitHub Desktop.
Save julianshapiro/9098609 to your computer and use it in GitHub Desktop.
Future-Proof IE Version Detection Without User Agent Sniffing
var IE = (function() {
if (document.documentMode) {
return document.documentMode;
} else {
for (var i = 7; i > 4; i--) {
var div = document.createElement("div");
div.innerHTML = "<!--[if IE " + i + "]><span></span><![endif]-->";
if (div.getElementsByTagName("span").length) {
div = null;
return i;
}
}
}
return undefined;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment