仅当存储事件由另一个窗口触发时,才会触发存储事件处理程序。您可以尝试运行以下代码:
// event handler window.addEventListener('storage', storageEventHandlerFunc, false); function storageEventHandlerFunc(evt) { alert("Storage event called key: " + event.key ); switch(event.key){ case 'one': case 'two': batteryDCMeter(); break; case 'extPowerOn': rechargeBattery(); break; } } sessionStorage.setItem("someKey", "someValue");