If I create a cookie in Javascript document.cookie = 'unseen'
how do I delete it when I navigate away from this page? This is the only cookie I am creating on the page.
views:
211answers:
3
A:
delete document.cookie
anyways i'm not sure if this is the right way to deal with cookies.
markcial
2010-03-18 16:05:22
+2
A:
Run this:
document.cookie = 'unseen=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
You're not deleting it, but telling the browser it's expired so it'll delete it.
Nick Craver
2010-03-18 16:06:14
Thanks. Should do it on page unload event?
Victor
2010-03-18 16:07:47
@VictorS - Yep, whenever you want to get rid of it.
Nick Craver
2010-03-18 16:08:06
Yeah, I want to get rid of it when navigating away from this page
Victor
2010-03-18 16:09:11
By the way this is a content page but it shouldn't matter
Victor
2010-03-18 16:10:00
@VictorS - Correct, to the user it's just a html page...just rig up to onunload in your case. But since this will happen only inside the page...do you really need a cookie? Seems like it's just a variable unless I'm missing something.
Nick Craver
2010-03-18 16:14:22
I need to supress alert message that I pop-up when this page is saved
Victor
2010-03-18 16:54:47
A:
Set it it to expire to a time in the past. Function from http://techpatterns.com/downloads/javascript_cookies.php
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
Dustin Laine
2010-03-18 16:07:31