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.

没有正确的解决方案

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top