I am pretty new to this cookie stuff. I have a requirement where I need to set a cookie on the TLD (www.example.co.uk) from one of the subdomains (sub.example.co.uk) using Javascript. First of all, is it possible? if yes, how do I go about doing that? Any help on this would be highly appreciated.
Thanks, L
I think you are confused about the definition of a TLD. You cannot set a cookie on a TLD. You can try to set a cookie on a different domain, but the browser may or may not accept it (look into the P3P header). I would set it in a shared domain. In your example, it would be .example.co.uk and would work for www.example.co.uk and sub.example.co.uk.
Try this (untested):
document.cookie = "name=value; expires=date; path=path; domain=.example.co.uk";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With