Monday, March 17, 2008

Who ate my cookie! (and other puns about browser cookies)

Recently I learned, on accident, how to create a session cookie in JavaScript (which was causing a bug in the Campfire Growl Script).

  function setCookie(name, value) { document.cookie = (name + "=" + escape(value)); }

Here's how to NOT create a session cookie:

  function setCookie(name, value, days) { 
    expire_str = days ? ";expires="+(new Date(new Date().getTime() + days*24*60*60*1000)).toGMTString() : ""
    document.cookie = (name + "=" + escape(value)) + (expire_str); 

HINT: Specify an expiration date on the cookie

If the campfire growl script is forgetting your settings, update to the latest :)

No comments: