判斷瀏覽器設定相應的CSS

來源:互聯網
上載者:User
 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

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.