I was wonder if you can delete a cookie at the beginning of the next day.
Lets say I log in to a website at 开发者_JAVA技巧1:30pm and use it again throughout the day but at midnight or 1 minute past, in the new day, the cookie is removed.
Many thanks for any help, C
Yes - set an expiry time of midnight:
function midnight_cookie(name, value, path)
{
var now = new Date();
var expire = new Date();
expire.setFullYear(now.getFullYear());
expire.setMonth(now.getMonth());
expire.setDate(now.getDate()+1);
expire.setHours(0);
expire.setMinutes(0);
document.cookie = name+"="+value+"; expires=" + expire.toString() +"; path=" + path;
}
Give the cookie an appropriate expiry datetime.
You can let cookies expire on a given date / time. Have a look at the setCookie function here:
http://techpatterns.com/downloads/javascript_cookies.php
精彩评论