PDA

View Full Version : Need a cookie to set selected css?



marinebio
06-24-2008, 08:45 PM
Hi all,
I've just launched a new design for our site and have one last thing I'm having trouble with.... I have 5 css styles users can switch to via javascript links that changes the site's color scheme. It works great except I need it to stick via cookie so the selected css is used page to page and when users return to the site. I understand basic cookie concepts but am lost as to how to connect a cookie to the javascript function in question.
Here's the javascript switch function, css file links, and links that do the switch:

(function thanks to http://www.codelifter.com/main/javascript/changestyles.html):

function changeSheets(whichSheet){
whichSheet=whichSheet-1;
if(document.styleSheets){
var c = document.styleSheets.length;
for(var i=0;i<c;i++){
if(i!=whichSheet){
document.styleSheets[i].disabled=true;
}else{
document.styleSheets[i].disabled=false;}}}}

<style type="text/css">@import "/_n/s/blue_1.css";</style>
<style type="text/css">@import "/_n/s/aqua_2.css";</style>
<style type="text/css">@import "/_n/s/deep_3.css";</style>
<style type="text/css">@import "/_n/s/black_4.css";</style>
<style type="text/css">@import "/_n/s/purple_5.css";</style>
<style type="text/css">@import "/_n/s/blue_1.css";</style>

<a href="javascript:changeSheets(1)">switch 1</a>
<a href="javascript:changeSheets(2)">switch 2</a>
<a href="javascript:changeSheets(3)">switch 3</a>
<a href="javascript:changeSheets(4)">switch 4</a>
<a href="javascript:changeSheets(5)">switch 5</a>

I'd really appreciate any help and would be happy to make a donation to whoever helps me get this working properly...

marinebio
06-24-2008, 10:35 PM
Nevermind... somehow I missed http://www.dynamicdrive.com/dynamicindex9/stylesheetswitcher.htm - will try that instead. I must be tired...