Skip to content

Instantly share code, notes, and snippets.

@cristobal
Forked from anonymous/file1.ab
Created September 16, 2011 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristobal/1222914 to your computer and use it in GitHub Desktop.
Save cristobal/1222914 to your computer and use it in GitHub Desktop.
/**
* Test for IE
* - http://blogs.msdn.com/giorgio/archive/2009/04/14/how-to-detect-ie8-using-javascript-client-side.aspx
* - http://blogs.msdn.com/mikeormond/archive/2008/09/25/ie-8-compatibility-meta-tags-http-headers-user-agent-strings-etc-etc.aspx
* - http://msdn.microsoft.com/en-gb/library/cc817572.aspx
* - http://stackoverflow.com/questions/5825385/javascript-can-i-detect-ie9-if-its-in-ie7-or-ie8-compatibility-mode
*/
if(window.ActiveXObject){
var rv = -1;
var ua = navigator.userAgent;
var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");
if (re.test(ua)) {
rv = parseFloat(RegExp.$1);
}
var msie9 = (rv == 5) || ("performance" in window);
var msie8 = (rv == 4) && !msie9;
var msie7 = window.XMLHttpRequest && !(msie8 || msie9);
// var msie6 = (!!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1)) && /MSIE 6/i.test(navigator.userAgent);
// var msie6 = !(msie7 || msie8 || msie9);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment