Skip to content

Instantly share code, notes, and snippets.

@AgataJot
Created July 9, 2015 09:32
Show Gist options
  • Save AgataJot/5f8ae40104b6dd6452b2 to your computer and use it in GitHub Desktop.
Save AgataJot/5f8ae40104b6dd6452b2 to your computer and use it in GitHub Desktop.
detect IE
function detectIE() {
if (typeof window === 'undefined') {
return true;
}
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// IE 12 => return version number
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