-
-
Save cbfranklin/9b228da06106b61c9765 to your computer and use it in GitHub Desktop.
This file contains 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
var ieUserAgent = { | |
init: function () { | |
// Get the user agent string | |
var ua = navigator.userAgent; | |
this.compatibilityMode = false; | |
// Detect whether or not the browser is IE | |
var ieRegex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); | |
if (ieRegex.exec(ua) == null) | |
this.exception = "The user agent detected does not contai Internet Explorer."; | |
// Get the current "emulated" version of IE | |
this.renderVersion = parseFloat(RegExp.$1); | |
this.version = this.renderVersion; | |
// Check the browser version with the rest of the agent string to detect compatibility mode | |
if (ua.indexOf("Trident/6.0") > -1) { | |
if (ua.indexOf("MSIE 7.0") > -1) { | |
this.compatibilityMode = true; | |
this.version = 10; | |
} | |
} | |
else if (ua.indexOf("Trident/5.0") > -1) { | |
if (ua.indexOf("MSIE 7.0") > -1) { | |
this.compatibilityMode = true; | |
this.version = 9; | |
} | |
} | |
else if (ua.indexOf("Trident/4.0") > -1) { | |
if (ua.indexOf("MSIE 7.0") > -1) { | |
this.compatibilityMode = true; | |
this.version = 8; | |
} | |
} | |
else if (ua.indexOf("MSIE 7.0") > -1) | |
this.version = 7; | |
else | |
this.version = 6; | |
} | |
}; | |
// Initialize the ieUserAgent object | |
ieUserAgent.init(); | |
// Do stuff | |
if (ieUserAgent.compatibilityMode == true){ | |
if(ieUserAgent.version === 8){ | |
//trigger alert with ie8 instructions | |
} | |
if(ieUserAgent.version === 9){ | |
//trigger alert with ie9 instructions | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment