简体   繁体   中英

deleting cookie from parent domain

I am in "foo.bar.com", I am setting the cookie with key "abc" for the domain ".bar.com"

So far so good.

Now, I am still in "foo.bar.com" but I want to delete the cookie with key "abc" from domain ".bar.com"

How do I do that? I am doing JavaScript.

您需要明确提供域

document.cookie = 'abc=' + ";expires=Thu, 01 Jan 1970 00:00:01 GMT ;domain=.foo.com;path=/";

如果使用jquery.cookie ,则指定域和路径:

$.removeCookie('cookie_name', {domain: '.food', path:'/'});

While counter-intuitive, I've found the behavior seen by OP to be expected in both Chrome and Firefox. It's possible to create a cookie at a parent domain from a subdomain, but not possible to delete it afterward. This answer to another post describes this in a little more detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM