Javascript Cookie

cookiesjavascript

I have cookies for the domain .forum.mywebsite.com and for .mywebsite.com.

Is it possible to read the cookie for the .mywebsite.com domain with javascript from the forum.mywebsite.com location?

Best Answer

Yes you should be able to read it. Check the following articles

When the JavaScript set cookies process is invoked, the script either presents the browser with a domain, or a blank value. If no domain is given it is assumed to be the domain of the page i.e. java-programming.suite101.com in this case.

The JavaScript cookies path, on the other hand, allows the programmer to make sure that the cookie is only valid (sent to the server) for pages in a specific path on the website. So, specifying a path such as /blog would restrict the cookie to my.domain.com/blog. If the cookie should be applicable across the whole (sub)domain, then path=/ should be specified.

  1. Javascript Cookies
  2. Using Javascript Cookies

But you will not be able to delete the cookie from the subdomain. Check this question in SO : Is it possible to delete subdomain cookies?