I have an onbeforeunload event handler attached to the page which executes every time the page reloads / gets redirected.
window.onbeforeunload = function()
To add:
function f_beforeunload(e) {console.log("do something");} window.addEventListener("beforeunload", f_beforeunload);
To remove:
window.removeEventListener("beforeunload", f_beforeunload);