Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Detect IE Version
// Looks at User Agent to determine if IE and which version
function GetIEVersion() {
var sAgent = window.navigator.userAgent;
var idx = sAgent.indexOf("MSIE");
var versionNumber = 0;
// If IE, return version number.
if (idx) {
try {
versionNumber = parseInt(sAgent.substring(idx+ 5, sAgent.indexOf(".", idx)));
} catch (e) {
// swallow it
}
}
// If IE 11 then look for "Trident" in user agent string.
if (!versionNumber && !!navigator.userAgent.match(/trident/gi)) {
versionNumber = 11;
}
// If IE Edge then look for "Edge" in user agent string.
if (!versionNumber && !!navigator.userAgent.match(/edge/gi)) {
versionNumber = 13;
}
return versionNumber;
}
function GetIEVersion(){var t=window.navigator.userAgent,n=t.indexOf("MSIE"),e=0;if(n)try{e=parseInt(t.substring(n+5,t.indexOf(".",n)))}catch(t){}return!e&&navigator.userAgent.match(/trident/gi)&&(e=11),!e&&navigator.userAgent.match(/edge/gi)&&(e=13),e}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment