tags:

views:

42

answers:

1

Does anyone have a piece of javascript code that creates a cookie and stores an array in it? If you also have the code to read through through cookie and delete it, that would be great as well. Thanks!

+2  A: 

have a look at: http://plugins.jquery.com/project/cookie

to store an array

$.cookie('COOKIE_NAME', escape(myarray.join(',')), {expires:1234});

to get it back

cookie=unescape($.cookie('COOKIE_NAME'))
myarray=cookie.split(',')
Christian Smorra
If your data can contain special characters, you should use JSON encode/decode. Otherwise, an entry containing "," will give incorrect decode result.
HoLyVieR
Okay, thanks. I tried the jquery example above and couldn't get it to work properly. I may just be missing something. You can create cookies while not using a web server correct?
Josh
Dang. Yes, you need to have a web server for this... Was hoping not to. Thanks.
Josh
there is no way to create cookies without a webserver josh, if you want to test locally you need to setup a home package like xampp
Christian Smorra