Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
156 views
in Technique[技术] by (71.8m points)

javascript - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...