Firefox localStorage如何通过所有标签访问它? [英] Firefox localStorage how to access it across all tabs?

查看:106
本文介绍了Firefox localStorage如何通过所有标签访问它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只关心mozilla使用 localStorage 。当我将字符串存储到 localStorage



例如:

插入:

  localStorage [item] =hello; 

在标签B上,我要求使用相同的项目

  localStorage.getItem(item); 

如果我在Tab A中设置了值,不过,我之前在 Google Chrome 中使用了相同的代码,并且显示了全球特征。为什么它在 Mozilla Firefox 中不起作用办法??其他的stackoverflow线程据说使用 globalStorage ,但根据文档,这是一个不赞成的方法。



谢谢,



Aiden

解决方案

您可以尝试设置 localStorage value的值为:

  localStorage.setItem(item,hello); 

  localStorage.item =hello

根据规范,所有具有相同来源的文件共享相同的 localStorage 数据(不管实际访问 localStorage 的脚本的来源如何)。他们可以读取彼此的数据。他们可以覆盖对方的数据。但是具有不同来源的文档不能读取或覆盖彼此的数据(即使它们都从相同的第三方服务器运行脚本)。



这意味着您应该可以从不同的标签访问相同的 localStorage 日期。 b $ b

I am only concerned with mozilla's use of localStorage. When i store strings into localStorage

example:

on tab A, I insert:

localStorage["item"] = "hello";

on tab B, I request the same item using

localStorage.getItem("item");

I cannot access this item for some reason in Tab B if i set the the value in Tab A, however i have used the same code in Google Chrome before and it has shown Global characteristics.. why does it not work in Mozilla Firefox the same way?? Other stackoverflow threads have said to use globalStorage but that is a deprecated method according to documentation.

Thanks,

Aiden

解决方案

What you may try is to set the localStorage value as:

localStorage.setItem("item", "hello");

or

localStorage.item = "hello"

According to the specification all documents with the same origin share the same localStorage data (regardless of the origin of the scripts that actually access localStorage). They can read each other’s data. And they can overwrite each other’s data. But documents with different origins can never read or overwrite each other’s data (even if they’re both running a script from the same third-party server).

This means that you should be able to access the same localStorage date from different tabs.

这篇关于Firefox localStorage如何通过所有标签访问它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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