Reputation: 1087
How do I delete cookies via JavaScript when you refresh a page ? I wanted to do this using the event onbeforeunload
.
Upvotes: 3
Views: 20131
Reputation: 169403
Why you want to remove a cookie before it has a chance to be sent back to the server is beyond me, but here you go:
window.onbeforeunload = function(e) {
document.cookie = 'cookiename=; expires=' + d.toGMTString() + ';';
};
Upvotes: 3