日期:2014-05-17 浏览次数:20880 次
发现一些CSS属性存在Firefox不兼容的现象,所以只能先判断用户的浏览器类型再加载CSS文件了。
  写好适合各种浏览器的CSS代码后,只需把下面的代码放到网页的<head>与</head>之间就可以了:
<script 
language="javascript">
<!--
if(window.navigator.userAgent.indexOf("MSIE")>=1){
//如果浏览器为IE
setActiveStyleSheet("style1.css");
}
else 
if(window.navigator.userAgent.indexOf("Firefox")>=1){
//如果浏览器为Firefox
setActiveStyleSheet("style2.css");
}
else{
//如果浏览器为其它
setActiveStyleSheet("style3.css");
}
function 
setActiveStyleSheet(filename){ 
document.write("<link 
href=\"\/images\/"+filename+"\" type=\"text\/css\" 
rel=\"stylesheet\">");
}
//-->
</script> ?