-
-
Save mangowi/838d7e69193122bab0705b1cd826482c to your computer and use it in GitHub Desktop.
Detect if IE and add class to html/body..
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 '); | |
if (msie > 0) { | |
// IE 10 or older => return version number | |
var ieV = parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10); | |
document.querySelector('body').className += ' IE'; | |
} | |
var trident = ua.indexOf('Trident/'); | |
if (trident > 0) { | |
// IE 11 => return version number | |
var rv = ua.indexOf('rv:'); | |
var ieV = parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10); | |
document.querySelector('body').className += ' IE'; | |
} | |
var edge = ua.indexOf('Edge/'); | |
if (edge > 0) { | |
// IE 12 (aka Edge) => return version number | |
var ieV = parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); | |
document.querySelector('body').className += ' IE'; | |
} | |
// other browser | |
return false; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment