Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ----------------------------------------------------------
// 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

This comment has been minimized.

Copy link

@melvinwallerjr melvinwallerjr commented Jun 8, 2014

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
You can’t perform that action at this time.