
if (window.XMLHttpRequest) { //Mozilla, Safari,IE7
alert('Mozilla, Safari,IE7 ');
if (!window.ActiveXObject) { // Mozilla, Safari,
alert('Mozilla, Safari');
} else {
alert('IE7');
}
} else {
alert('IE6');
}
写法二:

if (window.XMLHttpRequest) //判断浏览器是否属于Mozilla,Sofari
{
alert("firefox");
} else if (window.ActiveXObject) //判断浏览器是否属于IE
{
var browser = navigator.appName
var b_version = navigator.appVersion
var version = b_version.split(";");
var trim_Version = version[1].replace(/[ ]/g, "");
if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE7.0") {
alert("IE 7.0");
} else if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE6.0") {
alert("IE 6.0");
}
}