How can I get an event to fire every time localStorage is updated in Safari 5+?

后端 未结 3 503
遥遥无期
遥遥无期 2020-12-18 23:58

I have tried to follow the examples on the Safari Developer Site.

The documentation suggests adding an event listener like so:

window.addEventListene         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 00:13

    I realize this is asking about Safari but, per the Mozilla Developer Network, the StorageEvent is only fired if the web storage object is changed from outside the page, e.g., in another tab.

    https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API

    Scroll down to "Responding to storage changes with the StorageEvent".

    (I would have added this as a comment to the accepted answer but I don't have the rep for that.)

提交回复
热议问题