5

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.

hrishikeshp19
  • 8,838
  • 26
  • 78
  • 141

3 Answers3

4

You need to explicitly provide the domain

document.cookie = 'abc=' + ";expires=Thu, 01 Jan 1970 00:00:01 GMT ;domain=.foo.com;path=/";
jJ'
  • 3,038
  • 32
  • 25
2

If you use jquery.cookie, you specify the domain and path:

$.removeCookie('cookie_name', {domain: '.food', path:'/'});
eebbesen
  • 5,070
  • 8
  • 48
  • 70
pcyim
  • 33
  • 4
  • This isn't a popular comment, but it worked for me. It allowed me to delete a cookie from .base.com from subsite.base.com – webber55 May 18 '17 at 12:30
2

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.

Jack Ratner
  • 121
  • 2