Web Storage中的storage事件

學習到這個對我來說的新事件,

https://developer.mozilla.org/en-US/docs/Web/Events/storage


http://tutorials.jenkov.com/html5/local-storage.html


第二個連結擷取我需要的重點:

Attaching a Storage Event Listener:

Attaching an event listener to a local storage object is done like this:


function onStorageEvent(storageEvent){

    alert("storage event");
}

window.addEventListener('storage', onStorageEvent, false);


The function onStorageEvent() is the event handler function.

The addEventListener() function call attaches the event handler function to storage events.

The storageEvent event object passed to the event handler function looks like this:


StorageEvent {
    key;          // name of the property set, changed etc.
    oldValue;     // old value of property before change
    newValue;     // new value of property after change
    url;          // url of page that made the change
    storageArea;  // localStorage or sessionStorage,
                  // depending on where the change happened.
}


You can access this storage event object from inside the event handler function.



留言

熱門文章