Using JavaScript I’d like to get the domain value for a specific cookie.
Is this possible? If so, how?
To clarify: I’m not looking for the value of the cookie. I’m on subdomain.example.com and I need to remove a cookie whose name is known but its domain value is something like .example.com. In short: I’d like to get the value of .example.com.
Sorry, all you get is what you see in
document.cookie. The cookie metadata likepath,domainandexpiresare not visible to site code (neither to JavaScript nor to the server-side).To read a cookie that is being shadowed by a cookie with a more-specific
domainorpath, the only thing you can do is load a page for which the more-specific cookie is out-of-scope, and read it from there.If, as you say, you only need to remove a cookie, what you could do is try to remove the cookie at every possible level of specificity, eg.:
and similarly with the
pathvariable. You could put this in a nested loop for each path and domain part, splitting on.for the domain and/for the path.