如何判断浏览器类型然后让它读取指定的CSS
<SCRIPT LANGUAGE="JavaScript">
<!--
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
//如果浏览器为IE
setActiveStyleSheet("default.css");
}else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
//如果浏览器为Firefox
setActiveStyleSheet("default2.css");
}else{
//如果浏览器为其他
setActiveStyleSheet("newsky.css");
}
}
function setActiveStyleSheet(title){ 
  document.getElementsByTagName("link")[0].href="style/"+title; 
}
//--></SCRIPT>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="" rel="stylesheet" type="text/css" id="link"/>
<SCRIPT>
function oo(obj){
        return typeof(obj)=="string"?document.getElementById(obj):obj
}
 if (window.navigator.userAgent.indexOf("MSIE")>=1){
        oo("link").href='1.css';
        alert("当前浏览器为IE,css文件为"+oo("link").href);
}else{
        if (window.navigator.userAgent.indexOf("Firefox")>=1){
              oo("link").href='2.css';
              alert("当前浏览器为Firefox,css文件为"+oo("link").href);
        }else{
              oo("link").href='3.css';
              alert("当前浏览器为其他,css文件为"+oo("link").href);
        }
 }
</SCRIPT>
</head>
<body>
</body>
</html>
                    
                
                
            
        
浙公网安备 33010602011771号