如何使用Javascript删除cookie? [英] How to remove a cookie by using Javascript?

查看:157
本文介绍了如何使用Javascript删除cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何移除

javascript:void(document.cookie="PREF=ID=20b6e4c2f44943bb:U=4bf292d46faad806:TM=1249677602:LM=1257919388:S=odm0Ys-53ZueXfZG;path=/; domain=.google.com");

以下语句不起作用。

javascript:void(document.cookie="PREF=ID=20b6e4c2f44943bb:U=4bf292d46faad806:TM=1249677602:LM=1257919388:S=odm0Ys-53ZueXfZG;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/; domain=.google.com");

删除代码有什么问题?

推荐答案

Trick是正确的...特别是你需要在 expires 头中添加任何过去值。 (这些天你会使用一个全年,但两位数格式只能回到早期的Netscapes。)

Trick is right... in particular you need to put any past-value in the expires header. (These days you'd use a full-year, though; the two-digit format goes back to the early Netscapes only.)

还要确保你不使用

javascript:alert(document.cookie='PREF=X;path=/;domain=.google.com;expires=Sat, 01-Jan-2000 00:00:00 GMT');

请注意 Date.toGMTString 与cookie规范要求的日期格式相同,但仍然可以在许多浏览器中使用。

Note that the format produced by Date.toGMTString is not the same as the date format required by the cookie specification, although it does still work in many browsers.

这篇关于如何使用Javascript删除cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆