Closed Thread Icon

Topic awaiting preservation: Cookies not Working (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8664" title="Pages that link to Topic awaiting preservation: Cookies not Working (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Cookies not Working <span class="small">(Page 1 of 1)</span>\

 
quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 05-21-2003 11:39

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).]

viol
Maniac (V) Inmate

From: Charles River
Insane since: May 2002

posted posted 05-24-2003 10:12

I don't know why it's not working but the best get and set cookie functions that I know of are also the oldest ones around and you can get them here: http://www.webreference.com/javascript/960701/part01.html
I found that when you want your cookies to work with IE, Netscape, Mozilla and Opera, it's not easy to find a good cookie-management set of functions. But this one will work, as long as you don't touch it. If you change the path to path=/, for instance, as suggested by many experts, it will stop working in one of these browsers, don't remember which one.
Here's the site I have done as my final project for a course I have taken and it uses these set of functions to get and set and remember the style sheet to use. Don't laugh at the site's layout, please, because I am not a graphics guru. http://www.people.fas.harvard.edu/~viol/fp12/

« BackwardsOnwards »

Show Forum Drop Down Menu