Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
formatting for 1st answer on https://stackoverflow.com/questions/31757852/how-can-i-detect-internet-explorer-ie-and-microsoft-edge-using-javascript/32107845
const ieVersionInt = (function getIEVersionInt(){
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer') {
let ua = navigator.userAgent,
re = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
if (re.exec(ua) !== null){
rv = parseFloat( RegExp.$1 );
}
} else if(navigator.appName == "Netscape"){
// in IE 11 the navigator.appVersion says 'trident'
// in Edge the navigator.appVersion does not say trident
if (navigator.appVersion.indexOf('Trident') === -1) rv = 12;
else rv = 11;
}
return rv;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.