I want to be able to run a certain piece of code ONLY when the page is exited. I have tried this:
window.onbeforeunload = function(){
new Notification('Window unloaded');
return true;
}
However, if the user presses 'cancel,' then the notification still shows up. How can I make it so that the code only runs if the page is fully exited?