Cookies

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Yumm Yumm
Forum Newbie
Posts: 6
Joined: Sat Apr 12, 2003 3:59 am

Cookies

Post by Yumm Yumm »

i wrote a cookie with javascript, but for some reason my code only reads the cookie when u refreash. when u close the browser and return to the site my code wont read the cookie, can some one help me???

heres my JS for reading the cookie

var your_cookie=document.cookie;
if(your_cookie.length>1)
{
var your_cookie = unescape(your_cookie);
break_cookie=your_cookie.split("/");
for(count=0;break_cookie[count].length>1;count++)
{
cookie_value=break_cookie[count].split("&");
shoppingcart(cookie_value[0],cookie_value[1]);
}


}
Yumm Yumm
Forum Newbie
Posts: 6
Joined: Sat Apr 12, 2003 3:59 am

Post by Yumm Yumm »

oh i got another question, how would u set a cookie with a numeric value instead of a string.trnx
Skyzyx
Forum Commoner
Posts: 42
Joined: Fri Feb 14, 2003 1:53 am
Location: San Jose, CA

Post by Skyzyx »

To answer your second question, just enter a numeric value instead of a string.

To answer your first question, yes - you do need to refresh the page before the cookie takes effect. That's the nature of cookies. Secondly, you've written what's called a "session-only" cookie, which means that the cookie will disappear once you close your browser. You need to add an expiration date to it so that it expires down the line instead of at the end of the session (which is closing your browser).
Post Reply