如何删除一个cookie
删除一个 Cookie
可以通过以下几种方式实现:
1. 将 Cookie 的过期时间设置为过去的时间:
var date = new Date();
date.setDate(date.getDate() - 1);
document.cookie = "cookieName=; expires=" + date.toUTCString();
将 cookieName
替换为要删除的 Cookie
的名称。
2. 使用expires
参数设置过期时间:
document.cookie = "cookieName=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
同样,将 cookieName
替换为要删除的 Cookie
的名称。
3. 使用max-age
参数设置过期时间:
document.cookie = "cookieName=; max-age=0";
同样,将 cookieName
替换为要删除的 Cookie
的名称。
请注意,删除 Cookie
时需要确保 path
和 domain
参数与要删除的 Cookie
的设置一致,以确保正确删除指定的 Cookie
THE END
暂无评论内容