How to select different CSS based on the browser? For example, I have three CSS files. If the client is IE6, css1 is used. If the client is IE7 or IE8, css2 is used. If the client is Firefox, css3 is used.
I found it online and said the following:
<! 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>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> automatically calls different CSS Code </Title>
<Link href = "" rel = "stylesheet" type = "text/CSS"/>
<Script language = "jscript">
If (window. Navigator. useragent. indexof ("MSIE")> = 1)
{
VaR ie1024 = "style1.css ";
VaR ie800 = "style2.css ";
VaR ie1152 = "css1.css ";
VaR ieother = "css1.css ";
Screenwidth (ie1024, ie800, ie1152, ieother)
} Else {
If (window. Navigator. useragent. indexof ("Firefox")> = 1)
{
// If the browser is Firefox
VaR firefox1024 = "style1 ";
VaR firefox800 = "style2.css ";
VaR firefox1152 = "css1.css ";
VaR firefoxother = "css1.css ";
Screenwidth (firefox1024, firefox800, firefox1152, firefoxother)
} Else {
// If the browser is other
VaR other1024 = "css1.css ";
VaR other800 = "css1.css ";
VaR other1152 = "css1.css ";
VaR otherother = "css1.css ";
Screenwidth (other1024, other800, other1152, otherother)
}
}
Function screenwidth (css1, css2, css3, css4 ){
If (screen. width = 1024) & (screen. Height = 768 )){
Setactivestylesheet (css1 );
} Else {
If (screen. width = 800) & (screen. Height = 600 )){
Setactivestylesheet (css2 );
} Else {
If (screen. width = 1152) & (screen. Height = 864 )){
Setactivestylesheet (css3 );
} Else {
Setactivestylesheet (css4 );
}}}
}
Function setactivestylesheet (title) {document. getelementsbytagname ("Link") [0]. href = "" + title ;}
</SCRIPT>
</Head>
<Body>
</Body>
</Html>