Xhtml+css method of multi-style selection for static page implementation

Source: Internet
Author: User
Tags date
css|xhtml| Static | Page bled = FALSE;
}
}
}

function Getactivestylesheet () {
var i, A;
for (i=0; (A = document.getElementsByTagName ("link") [i]); i++) {
if (A.getattribute ("rel"). IndexOf ("style")!=-1 && a.getattribute ("title") &&!a.disabled) return A.getattribute ("title");
}
return null;
}

function Getpreferredstylesheet () {
var i, A;
for (i=0; (A = document.getElementsByTagName ("link") [i]); i++) {
if (A.getattribute ("rel"). IndexOf ("style")!=-1
&& A.getattribute ("rel"). IndexOf ("alt") = = 1
&& A.getattribute ("title")
) return A.getattribute ("title");
}
return null;
}

function Createcookie (name,value,days) {
if (days) {
var date = new Date ();
Date.settime (Date.gettime () + (days*24*60*60*1000));
var expires = "; Expires= "+date.togmtstring ();
}
else expires = "";
Document.cookie = name+ "=" +value+expires+ "; path=/";
}

function Readcookie (name) {
var Nameeq = name + "=";
var ca = Document.cookie.split (';');
for (Var i=0;i < ca.length;i++) {
var c = Ca[i];
while (C.charat (0) = = ') c = c.substring (1,c.length);
if (C.indexof (nameeq) = = 0) return c.substring (nameeq.length,c.length);
}
return null;
}

Window.onload = function (e) {
var cookie = Readcookie ("style");
var title = cookie? Cookie:getpreferredstylesheet ();
Setactivestylesheet (title);
}

Window.onunload = function (e) {
var title = Getactivestylesheet ();
Createcookie ("style", title, 365);
}

var cookie = Readcookie ("style");
var title = cookie? Cookie:getpreferredstylesheet ();
Setactivestylesheet (title);

2, CSS calls:

CODE:
<link rel= "stylesheet" type= "Text/css" href= "default.css"/>//Default style this call
<link rel= "stylesheet" type= "Text/css" href= "One.css" title= "Name_one"/>//other styles such calls
<link rel= "stylesheet" type= "Text/css" href= "Two.css" title= "Name_two"/>
...

3, JS call:
CODE:
<script type= "Text/javascript" src= "Styleswitcher.js" ></script>

4, the realization of the choice of style:
Written in the body of the page

CODE:
<a href= "#"
> Default Style </a>
<a href= "#"
> Style one </a>
<a href= "#"
> Style two </a>

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.