Dynamic CSS, skin-changing technology

Source: Internet
Author: User
Tags setcookie domain
A common example of css| dynamic is that there are multiple page styles on a site that provide viewers with choices.

Also, when you select a style and then open the page again, the style remains.

Naturally think of Cookie technology

Here is the HTML code section (plus the CSS file you need to use):

<HTML>
<HEAD>
<link id= "Skin" rel= "stylesheet" type= "Text/css" >
<TITLE> Skin-changing technology </TITLE>
<script language=javascript>
<!--
function Setcookie (name,value) {
var argv=setcookie.arguments;
var argc=setcookie.arguments.length;
var expires= (2&LT;ARGC) argv[2]:null;
var path= (3&LT;ARGC) argv[3]:null;
var domain= (4&LT;ARGC) argv[4]:null;
var secure= (5&LT;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;
The following set the cookie time is 1 years, oneself casually set that time.
Setcookie ("Nowskin", Url,expdate, "/", null,false);
}
}
-->
</SCRIPT>
</HEAD>
<BODY>
<P> Please select the dropdown menu below to test the skin effect </P>
<a href=# >css.css</a>
<a href=# >css1.css</a>
<a href=# >css2.css</a>
<a href=# >css3.css</a>
<br>
<select >
<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.