HTML5 / JS storage event handler

前端 未结 4 774
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 17:26

I\'m using Safari webkit\'s engine together with HTML5 and JS to create an offline application now I\'m using the sessionStorage array to store status of my app

相关标签:
4条回答
  • 2020-12-31 18:04

    To communicate between multiple tabs we can use storage event. You store a data item in local storage and you will get to know that your local storage is updated.

    Check out the code.

          window.addEventListener("storage", storageEventHandler, false);
    
          function storageEventHandler(evt) {
            alert("storage updated");
          }
    
          function clickme() {
            localStorage.setItem("someKey", "someValue");
          }
    <button onclick="clickme()">Click Me</button>

    Note: storage event only fires in other tabs. Not inside the tab, you are in currently. click^ :)

    0 讨论(0)
  • 2020-12-31 18:07

    Could you provide some more code for how you are storing the keys? It works for me on Safari - http://jsfiddle.net/pvRgH/

    0 讨论(0)
  • 2020-12-31 18:10

    Storage event handlers only fire if the storage event is triggered from another window.

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

    0 讨论(0)
  • 2020-12-31 18:20

    the 'storage' event occurred by the other tab in the browser. When you change the storage in one page and addEventLister also in this page , the window can not catch the message.

    for example

    You have two page, pageOne change the storage , pageTwo will catch the 'storage' message and handle this, but pageOne couldn't catch the message.

    0 讨论(0)
提交回复
热议问题