HTML5 / JS storage event handler

JavascriptWeb DevelopmentFront End Scripts

Storage event handlers only fire if the storage event triggered by another window. You can try to run the following code:

// 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");
raja
Published on 10-Apr-2018 08:36:57
Advertisements