/    Sign up×
Community /Pin to ProfileBookmark

Problem with cookies – they just won’t go away.

Hi…
Can some one point out as to why my code does not work?
I’ve created some cookies like this:

[code]
var gotCookies = get_cookie(cookie_name);
var exdate = new Date();
exdate.setDate(exdate.getDate()+10);
if(gotCookies != null)
{
//var gotCookie = document.cookie.split(“; “);
//var old_selection = gotCookie[0].split(“, “);
var new_selection = cbId;
document.cookie = cookie_name+”=”+gotCookies + ‘,<‘ + escape(new_selection) + “>,expires=”+exdate.toGMTString() + ‘,path=/’;
}
else
{
// Write a new cookie
var new_selection = cbId;
document.cookie = cookie_name + ‘=<‘+escape(new_selection) + “>,expires=”+exdate.toGMTString() + ‘,path=/’;
}
[/code]

and when I run the “delete cookies” they don’t go away, only after I close the browser. I realize I set a 10 day life span,but if you delete them shouldn’t they go away? Here is how I delete them.

[code]
function delete_cookie(name)
{
document.cookie = name+’=””;expires=Fri, 14 Oct 2005 12:00:00 UTC;path=/’;
}
[/code]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledApr 14.2009 — remove the double quote in the delete function.
<i>
</i>document.cookie = name+'=[b][color=Red]""[/color][/b];expires=Fri, 14 Oct 2005 12:00:00 UTC;path=/';

also, so far i can remeber, expire date only accept GMT format.
Copy linkTweet thisAlerts:
@EJMauthorApr 14.2009 — Thanks for the reply. I made the modification as you suggested,but it didn't work. I have cleared the cookies, etc from the browser as well.
Copy linkTweet thisAlerts:
@ZeroKilledApr 14.2009 — did you used an expire date in GMT format? don't know where you went wrong, but here is a tutorial and a lightweight snippet of code to manage cookies. http://www.quirksmode.org/js/cookies.html
Copy linkTweet thisAlerts:
@budsterApr 14.2009 — Hi EJM

Most browsers treat cookies with a past expiry date as a session cookie, therefore the behaviour would be to delete it at the end of the session, as your experiencing. One solution would be to null the value of the cookie in your delete function, so when you read it it has no value. See http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11180 for an example.

Hope this helps
Copy linkTweet thisAlerts:
@Sterling_IsfineApr 14.2009 — Hi EJM

Most browsers treat cookies with a past expiry date as a session cookie, therefore the behaviour would be to delete it at the end of the session, [/QUOTE]
That's not right, a cookie assigned a valid past date clears immediately.
×

Success!

Help @EJM spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...