IE11或者非IE
if (!document.all) {
alert('IE11+ or not IE');
}
IE10
if (document.all && document.addEventListener && window.atob) {
alert('IE10');
}
IE9
if (document.all && document.addEventListener && !window.atob) {
alert('IE9');
}
IE8
if (document.all && document.querySelector && !document.addEventListener) {
alert('IE8');
}
IE7
if (document.all && window.XMLHttpRequest && !document.querySelector) {
alert('IE7');
}
IE6
if (document.all && document.compatMode && !window.XMLHttpRequest) {
alert('IE6');
}
判断各种浏览器类型及版本:
var browser = {};
var userAgent = navigator.userAgent.toLowerCase();
var s;
(s = userAgent.match(/msie ([\d.]+)/)) ? browser.ie = s[1] :
(s = userAgent.match(/firefox\/([\d.]+)/)) ? browser.firefox = s[1] :
(s = userAgent.match(/chrome\/([\d.]+)/)) ? browser.chrome = s[1] :
(s = userAgent.match(/opera.([\d.]+)/)) ? browser.opera = s[1] :
(s = userAgent.match(/version\/([\d.]+).*safari/)) ? browser.safari = s[1] : 0;
var version;
if (browser.ie) {
version ='ie'+ browser.ie;
} else if (browser.firefox) {
version = 'firefox ' + browser.firefox;
} else if (browser.chrome) {
version = 'chrome ' + browser.chrome;
} else if (browser.opera) {
version = 'opera ' + browser.opera;
} else if (browser.safari) {
version = 'safari ' + browser.safari;
} else {
version = '未知浏览器' ;
}
return version;