Search code examples
javascriptobject-detectionreload

Detection of reload button pressed in Java Script


How to detect whether the reload button is pressed and after that the the processes be held and after that reload. Like when reload is pressed or Ctrl + R then I want to save that it is reloaded in local storage.


Solution

  • The event handler for processing onbeforeunload events is the WindowEventHandlers mixin's onbeforeunload property. When a window is about to unload its resources, these events are triggered.

    window.onbeforeunload = function(m) {
      return 'Your Statement';
    };
    

    And you can refer to Mozilla docs for more because you didn't shared your source code. https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload