I am not sure if my question is related to this or not.
IE9 deletes this cookie after closing the browser (expected), but Chrome 12, Firefox 5 and Opera 11 do not. (During testing of the example below, each browser was closed after clicking βDelete Account.β Then they were reopened after a short period of time, and all but IE9 had cookies there.)
Use Case: Cookie expires one year after the last visit by the user. Deleting an account should delete the cookie.
Question:
(1/2) Why is IE9 doing the right (expected) thing and others not?
(2/2) How can I guarantee that all browsers will destroy this cookie?
Example:
login.html
<!doctype html> <html> <head> <title>Create Cookie Example</title> <script> function setCookie() { var expDate = new Date(); expDate.setDate(expDate.getDate() + 365); document.cookie = "fakeCookie=" + escape("fake value") + "; expires=" + expDate.toGMTString(); } </script> </head> <body onload="setCookie()"> <h1>Welcome</h1> <p>Lorem ipsum...</p> <hr size="1" /> <p><a href="profile.html">User Profile</a></p> </body> </html>
profile.html
<!doctype html> <html> <head> <title>Delete Cookie Example</title> <script> function deleteConfirm() { if ( confirm("Are you sure you want to delete your account? " + "All data will be lost; this action cannot be undone!") ) deleteConfirmed() else return false return true; } function deleteConfirmed() { document.cookie = "fakeCookie=; expires=Thu, 01-Jan-70 00:00:01 GMT"; } </script> </head> <body> <h1>User Profile</h1> <p>Lorem ipsum...</p> <hr size="1" /> <p><a href="index.html" onclick="return deleteConfirm()">Delete Account</a></p> </body> </html>
Edit: the original message is incorrectly identified by login.html as index.html (creating a circular link that re-creates the cookie when deleting the "account".)
source share