I'm trying to pass a value from one page to another using localStorage.
Both pages use a common JS file to get/set values from localStorage.
This page sets the value appropriately using localStorage.setItem('key', 'value')
: http://example.com/path/index.html
ip
is parsed from the query string and written to localStorage with key db_ip
.
When I try to do localStorage.getItem('db_ip')
on this page, then the item is not there: http://www.example.com/path/page.html
I'm reading specs that say "every Document object whose Window object's localStorage attribute's Storage object is associated with the same storage area", so this makes me think pages can have separate localStorage by having a different Storage object.
I can see the Storage object is different between the two pages. How to I make both pages use the same Storage object?
The localStorage
isin't per page, it's by domain. However like @bfavaretto mentionned, www.demandbaselabs.com and demandbaselabs.com aren't considered as the same domain.
Have a look at this answer to see how you can exchange client-side stored data between domains.
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