日期:2014-05-16  浏览次数:20330 次

javascript判断浏览器类型

第一种方法:

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; 
} 

?

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

?