/    Sign up×
Community /Pin to ProfileBookmark

Can someone explain what happens when a cookie expires?

Hey Guys,

What happens when a cookie expires? Does the browser automatically delete expired cookies?

I’ve set a cookie after a popover window is displayed so that the popover doesn’t display for another 3 days. However I’m not sure whether I need to compare the cookies expiry to the current time to find out whether to display the popover or not???

If I do need to compare the cookie expiry and the current time, how do I extract the cookie expiry and compare to the current time??

Thanks in advance!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledOct 25.2008 — when a cookie expire, the browser simply delete it. what i'm understanding is that you store in the cookie the time when it was created, so later you read the cookie and compare with actual time. in my opinion it don't make sense. what i would do is store a simply value that indicate that cookie exists, if it don't exist it mean: cookie has expired or user has cleared cookie. how would i know if three days has passed? simply because i give the cookie three days to expire from actual day:
<i>
</i>if(!/popup/.test(document.cookie)){ //if cookie don't exist;
var exp = new Date();
exp.setDate(exp.getDate() + 3);
document.cookie = 'popup=false; expires=' + exp.toGMTString();
// code for popup;
}


in this sample what i really doing is checking if the cookie named 'popup' exist, if it don't exist then create the cookie and open the popup.
×

Success!

Help @crunchynuts 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...