[thelist] JS: Cookie Madness

Tom Dell'Aringa pixelmech at yahoo.com
Tue Feb 3 14:52:19 CST 2004


--- Hassan Schroeder <hassan at webtuitive.com> wrote:

> Uh, `expireDate = new Date()` is *right now* and by the time you
> set the cookie it's already in the past, eh?
> 
> Presumably you want it to expire at (now + some_interval)  :-)

Ah this is true, but not the problem. Revised version below. The
problem is JS sees the ";" as the end of the STATEMENT and stops
evaluating. I've done some research via google on this, lots of
questions but no answers...

function SetCookie (cookieName, cookieValue, expireDate) 
{
   var today = new Date();
   var expireDate = new Date(today.getTime() + 28 * 24 * 60 * 60 *
1000); // plus 28 days
   document.cookie = cookieName + "=" + escape(cookieValue) + ";
expires=" + expireDate.toGMTString() + "; path=/";
   alert(document.cookie)
} 

Run this and you will get the name and value but NO expiry date or
path.

Tom

=====
http://www.pixelmech.com/ :: Web Development Services
http://www.DMXzone.com/ :: JavaScript Author / Every Friday!
http://www.thywordistruth.net/ :: Eternal Life

[Those who say that I am finished, and am through, will have to run over my dead body to beat me...]


More information about the thelist mailing list