How do I remove cookies when the browser is closed? [duplicate]
Possible Duplicate:
Clear cookies on browser close
When I close the browser, I want to remove cookies. How can I do this?
If you don't set an expiry date it defaults to expire at the end of the session . Refer this links -
jscookies
taken from here
function del_cookie(name) {
document.cookie = name +
'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
Now all you need to do is to call this del_cookie()
function passing it the name of whatever cookie it is that we wish to delete. The function will update the expiry date on the cookie to one long in the past so that the cookie will be considered to be expired and will be ignored by the browser exactly the same as if it didn't exist
to be used something like
<body onload="SetCookie()" onunload="del_cookie()">
You are looking for session cookies.
A tutorial on hwo to create them in JavaScript is available here.
精彩评论