当前位置: 代码迷 >> JavaScript >> javascript判断浏览器部类
  详细解决方案

javascript判断浏览器部类

热度:89   发布时间:2012-11-23 22:54:33.0
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'); 
} 

?

  相关解决方案