-
-
Save anhr/cfe85a8c014f5847d2d0 to your computer and use it in GitHub Desktop.
JavaScript IE Version Detection, IE6-10 and IE Mobile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------- | |
// 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 = ( !!window.ActiveXObject && +( /msie\s(\d+)/i.exec( navigator.userAgent )[1] ) ) || NaN; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes I see "Unable to get property '1' of undefined or null reference" because
/IEMobile/(\d+.?(\d+)?)/.exec( navigator.userAgent ) is null
if "IEMobile" string is not exists in the navigator.userAgent.
I have used a code below for resolving of problem:
var ieMobile = /IEMobile/(\d+.?(\d+)?)/.exec( navigator.userAgent );
ieMobile = ( !! window.ActiveXObject && ieMobile && (ieMobile.length >= 2) && +( ieMobile[1] ) ) || NaN;