判断浏览器

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>

很多次用到判断浏览器的问题,每次都是网上找找,总结一下放到网上供大家,以后自己查看

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
Broswer Judge
</title>
<script type="text/javascript">
function getOs()
{
if(navigator.userAgent.indexOf("MSIE")>0)return 1;
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;
if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 3;
if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 4;
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)return 5;
return 0;
}
function judgeBroswer1(){
switch(getOs())
{
case 1:alert("IE");break;
case 2:alert("FireFox");break;
case 3:alert("Safari");break;
case 0:alert("Sorry,I can't judge the broswer right!");break;
}
}
function judgeBroswer2(){
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
if (window.ActiveXObject)
Sys.ie = ua.match(/msie ([\d.]+)/)[1]
else if (document.getBoxObjectFor)
Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1]
else if (window.MessageEvent && !document.getBoxObjectFor)
Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1]
else if (window.opera)
Sys.opera = ua.match(/opera.([\d.]+)/)[1]
else if (window.openDatabase)
Sys.safari = ua.match(/version\/([\d.]+)/)[1];


if(Sys.ie) alert('IE: '+Sys.ie);
if(Sys.firefox) alert('Firefox: '+Sys.firefox);
if(Sys.chrome) alert('Chrome: '+Sys.chrome);
if(Sys.opera) alert('Opera: '+Sys.opera);
if(Sys.safari) alert('Safari: '+Sys.safari);
}
</script>
</head>
<body>
<input type="button" id="judge1" value="judge1" onClick="judgeBroswer1()" />
<input type="button" id="judge2" value="judge2" onClick="judgeBroswer2()"/>
</body>
</html>

你可能感兴趣的:(浏览器,chrome,IE,firefox,Safari)