Dynamic CSS website tutorial: multiple page styles provide choice of visitors

Source: Internet
Author: User

On the cnbruce's blog, you can see this instant style changeCodeCopy the file for backup.
As shown in the following example, a website has multiple page styles to provide viewer selection. at the same time, after you select a style and open the page again, the style will remain unchanged. we naturally think of cookie technology.

Program code
<HTML>
<Head>
<Link id = "skin" rel = "stylesheet" type = "text/CSS">
<Title> skin Replacement Technology </title>
<Script language = JavaScript>
<! --
Function setcookie (name, value ){
VaR argv = setcookie. arguments;
VaR argc = setcookie. Arguments. length;
VaR expires = (2 <argc )? Argv [2]: NULL;
VaR Path = (3 <argc )? Argv [3]: NULL;
VaR domain = (4 <argc )? Argv [4]: NULL;
VaR secure = (5 <argc )? Argv [5]: false;
Document. Cookie = Name + "=" + escape (value) + (expires = NULL )? "" :( "; Expires =" + expires. togmtstring () + (Path = NULL )? "" :( "; Path =" + path) + (domain = NULL )? "" :( "; Domain =" + domain) + (secure = true )? "; Secure ":"");
}

Function getcookie (name ){
VaR search = Name + "= ";
VaR returnvalue = "";
If (document. Cookie. length> 0 ){
Offset = Document. Cookie. indexof (Search );
If (offset! =-1 ){
Offset + = search. length;
End = Document. Cookie. indexof (";", offset );
If (END =-1)
End = Document. Cookie. length;
Returnvalue = Unescape (document. Cookie. substring (offset, end ));
}
}
Return returnvalue;
}

VaR thisskin;
Thisskin = getcookie ("nowskin ");
If (thisskin! = "")
Skin. href = thisskin;
Else
Skin. href = "css.css ";

Function changecss (URL ){
If (URL! = ""){
Skin. href = URL;
VaR expdate = new date ();
Expdate. settime (expdate. gettime () + (24*60*60*1000*30 ));
// Expdate = NULL;
// Set the cookie time to one year ..
Setcookie ("nowskin", URL, expdate, "/", null, false );
}
}
// -->
</SCRIPT>
</Head>
<Body>

<P> select the drop-down menu below to test the skin replacement effect. </P>

<A href = # onclick = "changecss(''css.css ')"> css.css </a>
<A href = # onclick = "changecss(''css1.css'') "> css1.css </a>
<A href = # onclick = "changecss(''css2.css'') "> css2.css </a>
<A href = # onclick = "changecss(''css3.css ')"> css3.css </a>
<Br>

<Select onchange = "changecss (this. Value)">
<Option> select a style sheet file </option>
<Script language = "JavaScript">
VaR CSSS = new array ();
CSSS [0] = "css.css ";
CSSS [1] = "css1.css ";
CSSS [2] = "css2.css ";
CSSS [3] = "css3.css ";
VaR I;
For (I = 0; I <4; I ++)
If (thisskin = CSSS [I])
Document. write ("<option value = \" "+ CSSS [I] +" \ "selected>" + CSSS [I] + "style sheet file </option> ");
Else
Document. Write ("<option value = \" "+ CSSS [I] +" \ ">" + CSSS [I] + "style sheet file </option> ");
</SCRIPT>
</SELECT>
</Body>
</Html>

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.