Reputation: 1166
I am trying to add a popup pause in one day using JS cookies. Here is teh code:
if (document.cookie.indexOf("expirator") >= 0) {
// do not show popup
}
else{
var d = new Date();
var start_date = d.toUTCString();
d.setTime(d.getTime() + (1*24*60*60*1000));
var expireDate = "expires="+d.toUTCString();
document.cookie = "expirator=1;" + expireDate + "; domain=a5w.org; path=/";
// show popup
}
for a strange reason this scipt adds multiple new cookies with the same name ("expirator") instead of updating one. why is that so?
screenshot from FF cookies:
http://a5w.org/up/uploads/mike/2015-10-10/1444519970_cookies.png
Upvotes: 0
Views: 304
Reputation: 8380
You don't update cookies; you need to overwrite them.
Two cookies may have the same name if they were set for different domains or paths.
https://stackoverflow.com/a/1242446/280842
EDIT
There seems to be a bug in Firefox that displays multiple cookies in Firefox cookie manager. See https://bugzilla.mozilla.org/show_bug.cgi?id=504086
Upvotes: 2