为什么两个网页有不同的localStorage?我怎样才能解决这个问题? [英] Why do two web pages have different localStorage? How can I fix this?
问题描述
我试图使用localStorage将一个页面的值传递给另一个页面。
这两个页面都使用常用的JS文件从localStorage获取/设置值。
此页面使用 localStorage.setItem('key','value')
适当地设置值: http://demandbaselabs.com/dnb/index.html
ip
是从查询字符串中解析出来的,并使用键 db_ip
写入localStorage中。
当我尝试在此页面上执行 localStorage.getItem('db_ip')
时,该项目不存在: http://www.demandbaselabs.com/dnb/dnb.html
米阅读规格是说每个文档对象,其Window对象的localStorage的属性的存储对象相关具有相同的存储区域,所以这使得我认为页面可以通过具有不同的存储对象来分离localStorage。
我可以看到存储ob两页之间的项目不同。如何使两个页面使用相同的存储对象?
有一个在这个答案,以了解如何在域之间交换客户端存储的数据。
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://demandbaselabs.com/dnb/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.demandbaselabs.com/dnb/dnb.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.
这篇关于为什么两个网页有不同的localStorage?我怎样才能解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!