Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do two web pages have different localStorage? How can I fix this?

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?

like image 998
theUtherSide Avatar asked Sep 10 '13 01:09

theUtherSide


1 Answers

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.

like image 50
plalx Avatar answered Oct 24 '22 09:10

plalx