--- title: WindowEventHandlers.onstorage slug: Web/API/WindowEventHandlers/onstorage tags: - API - Web Storage - WindowEventHandlers - 属性 translation_of: Web/API/WindowEventHandlers/onstorage ---
WindowEventHandlers.onstorage 属性包含一个在{{event("storage")}}事件触发时的事件句柄。
注意:该事件不在导致数据变化的当前页面触发(如果浏览器同时打开一个域名下面的多个页面,当其中的一个页面改变 sessionStorage 或 localStorage 的数据时,其他所有页面的 storage 事件会被触发,而原始页面并不触发 storage 事件)
windowObj.onstorage = function() { ... };
window.onstorage = function(e) {
console.log( e.key + ' 键已经从 ' + e.oldValue + ' 改变为 ' + e.newValue + '.');
};
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('HTML WHATWG','webappapis.html#handler-window-onstorage','onstorage')}} | {{Spec2('HTML WHATWG')}} |