Skip to content

Instantly share code, notes, and snippets.

@jesusmacedo
Created January 25, 2016 19:06
Show Gist options
  • Save jesusmacedo/58a64833839b182c1e46 to your computer and use it in GitHub Desktop.
Save jesusmacedo/58a64833839b182c1e46 to your computer and use it in GitHub Desktop.
Detect any version of IE
/**
* detect IE
* returns version of IE or false, if browser is not Internet Explorer
*/
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
// IE 10 or older => return version number
if (msie > 0)
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
var trident = ua.indexOf('Trident/');
// IE 11 => return version number
if (trident > 0) {
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
// Edge (IE 12+) => return version number
if (edge > 0)
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
// other browser
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment