Can you refer the following links, it may be help you to understand.
https://webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/
Load/Unload Event Handlers :
Web developers can make use of the load and unload events to do work at certain points in the lifetime of a web page.
The purpose of the load event is quite straightforward: To perform initial setup of a new page once it has loaded.
The unload event is comparatively mysterious. Whenever the user leaves a page it is "unloaded" and scripts can do some final cleanup.
The mysterious part is that "leaving the page" can mean one of a few things:
- The user closes the browser tab or window, resulting in the
destruction of the visible page.
- The browser navigates from the old page to a new page, resulting in
the destruction of the old visible page.
The Page Cache makes this even more interesting by adding a new navigation possibility:
- The browser navigates from the old page to a new page, but the old
visible page is suspended, hidden, and placed in the Page Cache.
Some existing stack answers also available for this :
window.onbeforeunload and window.onunload is not working in Firefox , Safari , Opera?