0

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.

Daffy
  • 841
  • 9
  • 23

1 Answers1

0

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.

turing_machine
  • 473
  • 3
  • 13
  • If the data does not need to be sent back and forth to the server on every http request, cookies are no longer the preferred method. Local storage object is a much better option for pure client-side operations. – iGanja Feb 28 '14 at 06:08
  • @iGanja seems like accessing data from a subdomain is much more complicating using local storage, as referenced by the OP. http://stackoverflow.com/questions/4026479/use-localstorage-across-subdomains – turing_machine Feb 28 '14 at 06:12
  • Hmm, I've never had issue with that. I may have to check into that further. – iGanja Feb 28 '14 at 06:14