Skip to content

Instantly share code, notes, and snippets.

@thushan
Created August 21, 2013 01:32
Show Gist options
  • Save thushan/6289416 to your computer and use it in GitHub Desktop.
Save thushan/6289416 to your computer and use it in GitHub Desktop.
Detect Internet Explorer and version.
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// isIE === undefined
// If you're in IE (>=5) then you can determine which version:
// isIE === 7; // IE7
// Thus, to detect IE:
// if (isIE) {}
// And to detect the version:
// isIE === 6 // IE6
// isIE > 7 // IE8, IE9, IE10 ...
// isIE < 9 // Anything less than IE9
// ----------------------------------------------------------
// Credits http://stackoverflow.com/a/16657946
// ----------------------------------------------------------
var isIE = (function(){
var undef,rv = -1; // Return value assumes failure.
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 );
}
return ((rv > -1) ? rv : undef);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment