Is there any way to determine if the user clicked on a link, the forward or back button or entered a new URL in the address bar, in the following event?
$(window).unload(function(e) {
// here
}
Browsers can't distinguish between tab close, browser close, refresh, new address entered. All will trigger an unload event - the DOM is unloaded. Unfortunately there's no data passed to the unload event handler to distinguish between the different causes.
You could possibly do something with the mouse position - determine if the pointer is at the middle-top (for address bar), or right/left top for close. However its not a great solution as different browsers have their buttons in different positions, and Mac/PC have close buttons on opposite sides.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With