Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storage event not firing

Attaching the event:

$(window).on("storage", function (e) {    //callback not getting hit }); 

Trying to fire the event:

localStorage.setItem("test", "123"); 

I have two tabs open, both listening to the storage event. I can see the localStorage getting updated correctly on both tabs. However when I change localStorage on one tab, the other never fires the event. Any ideas?

Tried on Chrome/Firefox. Domain format is https://www.xxx.yyy.zzz.

like image 200
MichaelAttard Avatar asked Mar 08 '16 10:03

MichaelAttard


People also ask

What event is fired after web storage update?

The storage event of the Window interface fires when a storage area ( localStorage ) has been modified in the context of another document.

What is storage event in Javascript?

Definition and Usage The storage event occurs when there is a change in the window's change area. Note: The storage event is only triggered when a window other than itself makes the changes.


1 Answers

StorageEvent is fired in different page with the same domain.

From MDN

The StorageEvent is fired whenever a change is made to the Storage object.

This won't work on the same page that is making the changes — it is really a way for other pages on the domain using the storage to sync any changes that are made。

like image 193
Perry2008084 Avatar answered Sep 18 '22 12:09

Perry2008084