How to remove a cookie by using Javascript?

后端 未结 5 1366
后悔当初
后悔当初 2021-01-17 09:00

How to remove the cookie set by

javascript:void(document.cookie=”PREF=ID=20b6e4c2f44943bb:U=4bf292d46faad806:TM=1249677602:LM=1257919388:S=odm0Ys-53ZueXfZG;p         


        
5条回答
  •  误落风尘
    2021-01-17 09:54

    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.)

    Also ensure you don't use smart quotes like in your quote above.

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

    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.

提交回复
热议问题