[英]Scope of sessionStorage and localStorage
I read some documentation on sessionStorage and localStorage, but I don't understand what the scope is: the domain, a specific page? 我阅读了一些有关sessionStorage和localStorage的文档,但是我不明白范围是什么:域,特定页面?
For example, if I have the following pages: 例如,如果我有以下页面:
http://example.com/products.aspx?productID=1 http://example.com/products.aspx?productID=1
http://example.com/products.aspx?productID=2 http://example.com/products.aspx?productID=2
http://example.com/services.aspx?serviceID=3 http://example.com/services.aspx?serviceID=3
And if on each of the above pages I run (with idvalue being the value in the querystring): 并且如果在以上每个页面上运行(idvalue是查询字符串中的值):
localStorage.setItem('ID',idvalue);
Am I going to end up with 3 different values stored, or are the values going to overwrite each other? 我最终会存储3个不同的值,还是两个值会相互覆盖?
Session Storage: 会话存储:
Values persist only as long as the window or tab in which they stored. 值仅在存储它们的窗口或选项卡时持续存在。
Values are only visible within the window or tab that created them. 值仅在创建它们的窗口或选项卡中可见。
Local Storage: 本地存储:
Values persist window and browser lifetimes. 值保留窗口和浏览器的生命周期。
Values are shared across every window or tab running at the same origin. 值在同一来源运行的每个窗口或选项卡之间共享。
So, by reading and understanding this each key-value pair is unique for each domain, because local storage persist values across window or tab. 因此,通过阅读和理解这一点,每个键值对在每个域中都是唯一的,因为本地存储会在窗口或选项卡之间持久保存值。
The values are going to overwrite each other. 这些值将相互覆盖。 Each key-name pair is unique for a protocol and domain, regardless of the paths.
每个密钥名称对对于协议和域而言都是唯一的,而与路径无关。
The affected domain can be changed via the document.domain
property. 可以通过
document.domain
属性更改受影响的域。
sub.example.com
-> example.com
is possible (subdomain) sub.example.com
> example.com
是可能的(子域) sub.example.com
-> other.example.com
is not possible sub.example.com
> other.example.com
是不可能的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.