Dynamic CSS Switch

Source: Internet
Author: User

// Use different color schemes for different numbers in the root category:
// The initial order is: the URL sequence is the highest, followed by the cookie value.

// Extract the variable value from the URL string
Function getqueryvalue (sorstr, panstr)
{
VaR vstr = "";
If (sorstr = NULL | sorstr = "" | panstr = NULL | panstr = "") return vstr;
Sorstr = sorstr. tolowercase ();
Panstr + = "= ";
VaR itmp = sorstr. indexof (panstr );
If (itmp <0) {return vstr ;}
Sorstr = sorstr. substr (itmp + panstr. Length );
Itmp = sorstr. indexof ("&");
If (itmp <0)
{
Return sorstr;
}
Else
{
Sorstr = sorstr. substr (0, itmp );
Return sorstr;
}
}

Function getcookieval (offset)
{
VaR endstr = Document. Cookie. indexof (';', offset );
If (endstr =-1) endstr = Document. Cookie. length;
Return Unescape (document. Cookie. substring (offset, endstr ));
}

// Obtained from cookcie
Function getcookie (name)
{
VaR Arg = Name + '= ';
VaR Alen = Arg. length;
VaR clen = Document. Cookie. length;
VaR J = 0;
While (j <clen)
{
VaR K = J + Alen;
If (document. Cookie. substring (j, k) = Arg) return getcookieval (k );
J = Document. Cookie. indexof ('', j) + 1;
If (j = 0) break;
}
Return NULL;
}

// Obtain the URL string
VaR strgetquery = Document. Location. search;
// Obtain the csdnstyle numeric value
VaR stylevalue = getqueryvalue (strgetquery, 'csdnstyle ')

// If the URL is
If (stylevalue = '')
{
Stylevalue = getcookie ('sdnstyle ');
}
// Alert (stylevalue );
// Determine the CSS for selection
Switch (stylevalue)
{
Case '1 ':
Document. Write ('<LINK rel = "stylesheet" type = "text/CSS" href = "/expert/style/1.css"> ');
Break;
Case '2 ':
Document. Write ('<LINK rel = "stylesheet" type = "text/CSS" href = "/expert/style/2.css"> ');
Break;
Case '3 ':
Document. Write ('<LINK rel = "stylesheet" type = "text/CSS" href = "/expert/style/3.css"> ');
Break;
Case '4 ':
Document. Write ('<LINK rel = "stylesheet" type = "text/CSS" href = "/expert/style/4.css"> ');
Break;
Default:
Document. Write ('<LINK rel = "stylesheet" type = "text/CSS" href = "/expert/style/0.css"> ');
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.