在 Ajax 或其他相关的设计中,经常要判断浏览器的类型,以解决程序在不同浏览器下的兼容性问题。以下语句基本可以判断当前较流行的浏览器:
function CheckBrowser(){
var cb = "Unknown";
if(window.ActiveXObject){
cb = "IE";
}else if(navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
cb = "Firefox";
}else if((typeof document.implementation != "undefined") && (typeof document.implementation.createDocument != "undefined") && (typeof HTMLDocument != "undefined")){
cb = "Mozilla";
}else if(navigator.userAgent.toLowerCase().indexOf("opera") != -1){
cb = "Opera";
}
return cb;
}
点击:3282