Skip to content

Instantly share code, notes, and snippets.

@loslch
Last active December 15, 2017 00:09
Show Gist options
  • Save loslch/d92f07dc5ab8364b0140 to your computer and use it in GitHub Desktop.
Save loslch/d92f07dc5ab8364b0140 to your computer and use it in GitHub Desktop.
[JS] Get Internet Explorer Version
(function() {
var head;
function getInternetExplorerVersion()
{
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
else if (navigator.appName == 'Netscape')
{
var ua = navigator.userAgent;
var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
var version = getInternetExplorerVersion();
if(version > 9) {
head = document.getElementsByTagName("html")[0];
head.className = head.className + " ie";
if(version == 10) {
head.className = head.className + " ie10";
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment