Question

I need a client-sided domain-wide way to store a string that is accessible after the page has been closed and reopened. I tried localStorage, but if I store data on www.example.com, I cannot access it from sub.example.com. In this case, redirecting the user to the root host is not an option. I'd really prefer to not send messages to an iframe to store it because it would require completely rewriting the current code I have. Is there a way to store data with something like localStorage, but access it from other subdomains?

My goal is to have two simple functions, get() and set(value), that operate similar to how I've described.

No correct solution

OTHER TIPS

Try storing the data in a cookie, and ensure the cookie is configured to support subdomains.

For example, ".example.com", with the leading ".", will make the cookie available to all subdomains.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top