How to set cookies for a subdomain from the main domain?

The website written in the parameter "domain" to specify either the primary domain or its subdomain, but I can't create a cookie for with the website About the point before domain know. Interested in making cookies to a single subdomain, while on the main domain.
Sample code
var date = new Date(new Date().getTime() + 60 * 1000);
document.cookie = "name=value;; path=/; expires=" + date.toUTCString();
June 10th 19 at 15:33
3 answers
June 10th 19 at 15:35
Ask cook for one subdomain from the primary domain is impossible. You can only create shared cookie for all subdomains and main domain, specifying the domain parameter domain of the website.
A more detailed answer received here
June 10th 19 at 15:37
June 10th 19 at 15:39
I recommend to work with cookies good mini library.
When you work with it to solve
cookies({ cookieKey: 'value' }, { domain: '' });

Find more questions by tags HTTP CookiesJavaScript