Getting Or Setting Cookies With Javascript
Solution 1:
I can't answer why the cookie is not showing in your Vista folder, but that code properly sets and reads cookies as intended. How are you testing it? An easier way to test whether the cookies are sticking is by simply doing something like this:
<inputtype="button" value="Set" onClick="createCookie('test','yay',5);">
<inputtype="button" value="Read" onClick="alert(readCookie('test'));">
You can refresh the page between Setting and Reading it if makes you feel better, but it works for me.
If that doesn't show what you're expecting, make sure your browser is setup to accept cookies. :)
EDIT: Looking at your code, you missed replacing days
in this line:
date.setTime(date.getTime()+(days*24*60*60*1000));
Solution 2:
I'm testing it here: http://flamencopeko.net/cookie.php and here: http://flamencopeko.net/cookie.js. Works perfect.
And, yeah, Firebug's Cookies panel is great.
I'm trying to use your script to save font size preference. Here is a thread on that: simplify font size toggle.
Solution 3:
- Install Firefox
- Install FireBug
- Install FireCookies
- Download JQuery
- Download the Cookie plugin
Post a Comment for "Getting Or Setting Cookies With Javascript"