WindowEventHandlers.onstorage
属性包含一个在storage
事件触发时的事件句柄。
注意:该事件不在导致数据变化的当前页面触发(如果浏览器同时打开一个域名下面的多个页面,当其中的一个页面改变 sessionStorage
或 localStorage
的数据时,其他所有页面的 storage
事件会被触发,而原始页面并不触发 storage
事件)
语法
windowObj.onstorage = function() { ... };
用例
window.onstorage = function(e) {
console.log( e.key + ' 键已经从 ' + e.oldValue + ' 改变为 ' + e.newValue + '.');
};
说明书
Specification | Status | Comment |
---|---|---|
HTML Living Standard onstorage |
Living Standard |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | ? | 45 (45) | ? | ? | ? |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | ? | ? | 45.0 (45) | ? | ? | ? | ? | ? |