Forum Moderators: open

Message Too Old, No Replies

Need a cookie to set selected css?

         

marinebio

7:38 pm on Jun 24, 2008 (gmt 0)

10+ Year Member



Hi all,
Great forums. 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 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 the help and would be happy to make a donation to whoever helps me get this working properly.

marinebio

10:35 pm on Jun 24, 2008 (gmt 0)

10+ Year Member



Just found [dynamicdrive.com...] so nevermind...