I grabbed a cookie script from the FAQ to remember which colourscheme a user had selected on a site I have. Here is the code:
code:
function pass(scheme) {
//find cookie if page has called for previous scheme
if (scheme == "previous") {
var name = "colscheme";
var cookies = document.cookie;
if (cookies.indexOf(name) != -1){
var startpos = cookies.indexOf(name)+name.length+1;
var endpos = cookies.indexOf(";",startpos)-1;
if (endpos == -2) endpos = cookies.length;
pass(unescape(cookies.substring(startpos,endpos)));
}
} else {
//colourize is a function that actually gets the crayons out and colours in the page
if (scheme == "blue") {
colourize("#1db6e5","#007fa5");
}
if(scheme == "green") {
colourize("#A1CF99","#62ad46");
}
if(scheme == "pink") {
colourize("#F855B9","#003");
}
if(scheme == "brown") {
colourize("#A5CFCB","#ca9c5e")
}
if(scheme == "grey") {
colourize("#aaa","#444")
}
//remember scheme selected
var expire = new Date();
expire.setTime(expire.getTime() + 1000 * 60 * 60 * 24 * 365);
document.cookie = "colscheme="+scheme+"; expires="+expire.toGMTString()+";";
}
}
This seems, however, to be having no effect, i.e. it doesn't remember the scheme when I put onload="pass('previous');" in the body tag. Here is a link to the page in action, can anyone explain why it isn't working?
[This message has been edited by quisja (edited 05-21-2003).]