Aiden
Aiden

Reputation: 399

Firefox localStorage how to access it across all tabs?

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

Upvotes: 7

Views: 5175

Answers (1)

Endre Simo
Endre Simo

Reputation: 11541

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.

Upvotes: 4

Related Questions