判断浏览器类别

<html>
<title>判断浏览器类别</title>
<div>
<input type="button" onclick="chkBrowser()" value="test"/>
</div>
<script>
function chkBrowser()
{
	if(window.ActiveXObject){//MSIE 6.0 or below
		//判断是否是 IE 7以上
		if(document.documentElement && typeof document.documentElement.style.maxHeight != "undefined"){
		//判断是否是 IE 8+
		if(typeof document.adoptNode != "undefined"){//Safari3 & FF & Opera & Chrome & IE 8
		//MSIE 8.0 因为同事满足前两个if判断,所以在这里是IE 8
		}
		//MSIE 7.0 否则就是IE 7
		}
		alert("msie");
	}
	else if(typeof window.opera != "undefined"){//Opera 独占
	//"Opera"+window.opera.version()
	alert("opera");
	}
	else if(typeof window.netscape != "undefined"){//Mozilla 独占
	//"Mozilla"
	//可以准确识别大版本
	if(typeof window.Iterator != "undefined"){
	//Firefox2以上支持这个对象
	if(typeof document.styleSheetSets != "undefined"){//Firefox 3 & Opera 9
	//Firefox 3 同时满足这些条件的必然是Firefox 3了
		}
	}
	alert("mozilla");
	}
	else if(typeof window.pageXOffset != "undefined"){//Mozilla & Safari
	//"Safari"
	try{
	if(typeof external.AddSearchProvider != "undefined"){//Firefox & Google Chrome
	//Google Chrome
	alert("chrome");
	}
	}catch(e){
		alert("safari");
	}
	}else//unknown
	{//unknown
		alert("unknown");
	}
}
</script>
</html>

你可能感兴趣的:(判断浏览器类别)