1

Is the unload event triggered when the page is reloaded by the location.reload() method?

window.addEventListener('unload', function(event) {
    console.log('unload event was triggered');
});
location.reload();  // reload the current URL
Gorisanson
  • 2,202
  • 1
  • 9
  • 25
  • You can use `beforeunload` event instead `unload` – Denis Stukalov May 12 '20 at 13:58
  • I'm seeing an issue where unload isn't triggered in this case. Is this what you found too? What browser btw – pushkin Apr 08 '21 at 17:01
  • @pushkin When I have tested `location.reload()` after adding an event listener for `unload` event, I found that the `unload` event was triggered in Chrome, FireFox, and Safari browser. I have tested in the web consoles of each browser with ["preserve log" option turned on](https://stackoverflow.com/a/50977830/8581025). – Gorisanson Apr 09 '21 at 10:16

0 Answers0