Why cookie is not expiring?

I am using this method to set cookie however it just stay there doesn’t get removed after expiration why?

Please need help.

function setAgreeCookie() {
    var expire=new Date();
    expire=new Date(expire.getTime()+(20*1000));
    document.cookie=\"cookie=1; expires=\"+expire;
}

Quotes only have to be escaped inside other quotes of the same kind… otherwise you’ll actually get a syntax error and the cookie won’t even be set. So just change that line to

document.cookie = "cookie=1; expires=" + expire;

and it should work.

1 Like

Works now thanks so much :slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.