判断浏览器设置相应的CSS

1 <link href="" rel="stylesheet" type="text/css" id="link"/>
2 <script type="text/javascript">
3 <!--
4 if (window.navigator.userAgent.indexOf("MSIE") >= 1)
5 {
6 //如果浏览器为IE
7 setActiveStyleSheet("ie8.css");
8 }
9 if (window.navigator.userAgent.indexOf("Firefox") >= 1)
10 {
11 //如果浏览器为Firefox
12 setActiveStyleSheet("firefox.css");
13 }
14 else
15 {
16 //如果浏览器为其他
17 setActiveStyleSheet("other.css");
18 }
19 function setActiveStyleSheet(title)
20 {
21 document.getElementsByTagName("link")[0].href = "url/" + title;
22 }
23 //-->
24 </script>
25 <!--[if lte IE 6]>
26 <link rel="stylesheet" type="text/css" href="url/ie6.css" />
27 <![endif]-->
28 <!--[if IE 7]>
29 <link rel="stylesheet" type="text/css" href="url/ie7.css" />
30 <![endif]-->

把代码放在<head>标签内就可以判断浏览器,来实现相应的CSS

如果有什么事情让你感到恐惧或者兴奋,那就去做吧!
原文地址:https://www.cnblogs.com/yaokoo/p/1702423.html