'JavaScript domain read cookie from subdomain
I have a simple question - is there any way to read subdomain cookie on main domain by JavaScript? For example: I set cookie 'hello' with value '2' in subdomain yeah.something.com and after that I want to read it on something.com. I tried to find answer for that but I found only information how to set cookie on subdomain by creating it on domain.
Solution 1:[1]
An ancient question, but better to have it answered You can do it by creating a cookie on the domain with a dot on the start to support reading from all subdomains and from the main domain as well:
document.cookie = "_id=MY_ID;domain=.example.com;expires=;SameSite=none;Secure";
Hope it will help other lookers like me :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Oded BD |