Last active
December 18, 2015 02:08
-
-
Save mattpavelle/5708358 to your computer and use it in GitHub Desktop.
Check the browser userAgent and determine if it is IE8+ or IE7- (counting compatibility mode as the +, not the -)
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
// usually code that works in IE8/9/10 will also work in IE8/9/10 in compatibility mode, but IE reports itself as IE7 | |
// or some such when running in compatibility mode... so let's pretend that IE9 in IE7 compatibility mode is IE9 | |
function checkVersion() { | |
var msg = "Not IE"; | |
var ver = -1; // assume failure | |
var ua = navigator.userAgent; | |
if (navigator.appName == 'Microsoft Internet Explorer') { | |
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); | |
if (re.exec(ua) != null) | |
ver = parseFloat( RegExp.$1 ); | |
} | |
if (ver > -1) { | |
// the version is usually valid | |
if (ver >= 8.0) | |
msg = "IE8+"; | |
// unless we're in Compatibility Mode | |
else if (ua.indexOf('Trident') !== -1) | |
msg = "IE8+CM"; | |
else | |
msg = "IE7-"; | |
} | |
alert( msg ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment