Skip to content

Instantly share code, notes, and snippets.

@tmaiaroto
Created June 17, 2020 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmaiaroto/fcf2ca7c1196ef3093e5c877ba8233f3 to your computer and use it in GitHub Desktop.
Save tmaiaroto/fcf2ca7c1196ef3093e5c877ba8233f3 to your computer and use it in GitHub Desktop.
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