-
事件触发条件:
storage事件只会在其他窗口或标签页修改localStorage时触发。在同一窗口中对localStorage的修改不会触发此事件。 -
事件处理: 可以通过监听
window对象的storage事件来处理:window.addEventListener('storage', function(event) { if (event.key === 'yourKey') { console.log('localStorage has changed:', event.newValue); } });