Skip to content

Instantly share code, notes, and snippets.

@make-sum
Created September 17, 2013 19:04
Show Gist options
  • Save make-sum/6599149 to your computer and use it in GitHub Desktop.
Save make-sum/6599149 to your computer and use it in GitHub Desktop.
IE browser detect, including ie version, and ie document mode.
var ua = navigator.userAgent;
var isIE = ua.indexOf("MSIE") != -1;
var ieVersion;
var mode = document.documentMode ||
((/back/i).test(document.compatMode || "") ? 5 : ieVersion) ||
((/MSIE\s*(\d+\.?\d*)/i).test(navigator.userAgent || "") ? parseFloat(RegExp.$1, 10) : null);
function getIEVersion(dataString) {
var index = dataString.indexOf("MSIE");
if (index == -1) return;
return parseFloat(dataString.substring(index+5));
}
if(isIE) {
ieVersion = getIEVersion(navigator.userAgent);
//alert('version '+ ieVersion);
if(ieVersion < 10) {
//alert('document.documentMode ' + document.documentMode);
if(mode < 7 || !mode) {
//do something here, example
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment