This is what I use, I think if you don't pass a date it expires at the end of the session:
Code:
//Sets a cookie. Send the name of the varible, the value, days until it expires - leave blank for no-expiration
function setCookie(cookieName, cookieValue, cookieExpiry) {
//If the date is not already in date format (i.e. days till expiry), and not missing
if (!(cookieExpiry instanceof Date) && cookieExpiry != null) {
//Convert the expiry date to the correct format
var expiryDate = new Date ();
expiryDate.setTime(expiryDate.getTime() + (cookieExpiry * 24 * 3600 * 1000));
cookieExpiry = expiryDate;
}
//Write the cookie, and the expiration date (if present)
document.cookie = cookieName + '=' + escape(cookieValue) + ((cookieExpiry == null) ? '' : '; expires=' + cookieExpiry.toGMTString());
return true;
}
If you want the rest of the JS file (reading/deleting cookies etc) just let me know.
Good idea. Here's the file, I think it all works fine. I added a function called sixMonths that returns the date plus six months, so that you can set cookies for that length of time.