Deleting Cookies
Deleting Cookies
Section titled “Deleting Cookies”Introduction
Section titled “Introduction”Delete a cookie by setting its expiration to a past date or max-age=0.
How to Delete
Section titled “How to Delete”// Set max-age to 0 or use a past datedocument.cookie = 'session=; max-age=0; path=/';
// Alternative: set expires to a past datedocument.cookie = 'session=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/';Important: Match the Path
Section titled “Important: Match the Path”// Cookies are identified by name + path + domain// To delete, you must match the same path and domain
// Set at path=/document.cookie = 'session=abc123; path=/';
// Delete with same pathdocument.cookie = 'session=; max-age=0; path=/';
// If set at path=/app, you must delete at path=/appdocument.cookie = 'session=; max-age=0; path=/app';Summary
Section titled “Summary”- Set
max-age=0or use a pastexpiresdate - Must match the cookie’s original path and domain
document.cookie = 'key=; max-age=0'removes a cookie- Deleting all cookies at once requires iterating and matching