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.
CodePudding user response:
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
CodePudding user response:
To save localStorage in browser on reload/refresh of page.
Add Javascript code as below
window.onload = function () {
alert(localStorage.variable) //comment this line to avoid alert box
localStorage.setItem("variable", "set a variable value");
}