Created
January 25, 2016 19:06
-
-
Save jesusmacedo/58a64833839b182c1e46 to your computer and use it in GitHub Desktop.
Detect any version of IE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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