[thelist] JS: Cookie Madness
liorean
liorean at f2o.org
Tue Feb 3 16:33:23 CST 2004
Tom Dell'Aringa wrote:
> So to be clear, you are saying the document.cookie property holds
> thus:
>
> name1=value1
> name2=value2
> name3=value3
Well, rather "name1=value1;name2=value2;name3=value3", but essentially, yes.
> And that the expiry date, path and domain aren't accessible via JS.
> In other words, the expiry date is for the WHOLE cookie, regardless
> of how many name/value pairs are there?
>
> - or -
>
> there really is only ONE name/value pair per cookie? (looking at my
> yahoo cookies, that seems to be the case which is why they set 4
> cookies probably) and when you retrieve the cookie, you should ONLY
> get the name/value pair and not the rest of the info?
Well, there is one name/value pair per cookie. The expiry date, the
path, the host (domain) and whether the server is secure is stored on a
per-cookie basis. Yes, the thought is that the only information you
should be able to get is the name/value pair.
> It seems the second one is correct. Having said all that, I still
> need to be able to SET my expiry date, yet my posted line won't do it
> since it thinks the ; is the end of the statement.
Yeah. Unless the newline is inserted by the mail programs on either
side, you're doing a classical mistake in JavaScript, one that I have
not seen in so long that I had forgotten about it. You have a newline
within a string. That is not allowed. (If that's not the problem, I
don't really know. Have you tried alerting the generated string after
construction, but before you write it to the cookie, to see that the
value is correct?)
> document.cookie = cookieName + "=" + escape(cookieValue) + ";
> expires=" + expireDate.toGMTString() + "; path=/;";
>
> Even though your function was much terser, you seemed to follow the
> same convention (albeit without whitespace). Can I set the expiry
> date AFTER I set the value?
All should be set in a single string. It should come after the value in
that string, though.
--
liorean <mailto:liorean at user.bip.net>
ViewStyles, ViewScripts, ToggleStyles and GraphicsInfo bookmarklets and
Theme Switcher, Cookies Handler scripts:
<http://liorean.web-graphics.com/>
More information about the thelist
mailing list