Answer the question
In order to leave comments, you need to log in
How to set cookies for a subdomain from the main domain?
Hello.
The learn.javascript.ru site says that you can specify either the main domain or its subdomain in the "domain" parameter, but I can't create a cookie for one.example.com from the example.com site. About a point before domains I know. Interested in creating cookies for one subdomain while on the main domain.
Code Example
var date = new Date(new Date().getTime() + 60 * 1000);
document.cookie = "name=value; domain=learn.javascript.ru; path=/; expires=" + date.toUTCString();
Answer the question
In order to leave comments, you need to log in
You cannot set a cookie for one subdomain from the main domain. You can only create a common cookie for all subdomains and the main domain by specifying the site domain in the domain parameter.
More detailed answer here
I recommend a good mini-library for working with cookies .
When working with it, it is solved like this:
cookies({ cookieKey: 'value' }, { domain: 'sub.example.com' });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question