Skip to content

Instantly share code, notes, and snippets.

@peteboere
Forked from padolsey/gist:527683
Last active September 24, 2015 21:48
Show Gist options
  • Save peteboere/814550 to your computer and use it in GitHub Desktop.
Save peteboere/814550 to your computer and use it in GitHub Desktop.
// ----------------------------------------------------------
// A short snippet for detecting versions of IE:
// Uses a combination of object detection and user-agent
// sniffing.
// ----------------------------------------------------------
// If you're not in IE then:
// ie === NaN // falsy
// If you're in IE then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
// And to detect the version:
// ie === 6 // IE6
// ie > 7 // IE8, IE9 ...
// ie < 9 // Anything less than IE9
// ----------------------------------------------------------
var ie = ('ActiveXObject' in window && +(/\s(?:MSIE\s|rv\:)(\d+)/.exec(navigator.userAgent)[1])) || NaN
// The same thing but for IE Mobile instead.
var ieMobile = ( !! window.ActiveXObject && +( /IEMobile\/(\d+\.?(\d+)?)/.exec( navigator.userAgent )[1] ) ) || NaN;
@melvinwallerjr
Copy link

Testing for 'mise' in the userAgent string will not work for version 11 as Microsoft has remove that string. The closest thing you might use is 'trident'. You also cannot use 'IEMobile' to detect Tablet mobile devices as they use a version of Windows for desktop. You should additionally be careful to properly detect both the RT and full desktop versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment