sessionStorage和localStorage的范围 [英] Scope of sessionStorage and localStorage

查看:231
本文介绍了sessionStorage和localStorage的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sessionStorage和localStorage上阅读了一些文档,但我不明白范围是什么:域名,特定页面?

I read some documentation on sessionStorage and localStorage, but I don't understand what the scope is: the domain, a specific page?

例如,如果我有以下页面:

For example, if I have the following pages:

http:/ /example.com/products.aspx?productID=1

http://example.com/products.aspx?productID=2

http://example.com/services.aspx?serviceID=3

如果我在上面的每个页面上运行(idvalue是查询字符串中的值):

And if on each of the above pages I run (with idvalue being the value in the querystring):

localStorage.setItem('ID',idvalue);

我最终会存储3个不同的值,或者值是否会相互覆盖?

Am I going to end up with 3 different values stored, or are the values going to overwrite each other?

推荐答案

这些值将会相互覆盖。无论路径如何,每个密钥名对对于协议和域都是唯一的。

The values are going to overwrite each other. Each key-name pair is unique for a protocol and domain, regardless of the paths.

可以通过 document.domain更改受影响的域 property。

The affected domain can be changed via the document.domain property.


  • sub.example.com - > example.com 是可能的(子域名)

  • sub.example.com - > other.example.com 是不可能的

  • sub.example.com -> example.com is possible (subdomain)
  • sub.example.com -> other.example.com is not possible

这篇关于sessionStorage和localStorage的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆