The problem is as follows.
onbeforeunload
works like a charm in Firefox and has e.explicitOriginalTarget.activeElement
that shows what element has been clicked to cause it.
window.onbeforeunload = function(e){
if (e.explicitOriginalTarget.activeElement){
return;
}
In Chrome the 'e
' object looks identical when you close the window or click the link.
Is there any way to determine the target in chrome?
The onbeforeunload event occurs when the document is about to be unloaded. This event allows you to display a message in a confirmation dialog box to inform the user whether he/she wants to stay or leave the current page.
$(window). bind('beforeunload',function() { return "'Are you sure you want to leave the page. All data will be lost!"; }); $('#a_exit').
For what you are looking for, the best way to have control refreshing the webpage would be with the onKeyDown function. Unfortunately pressing the refresh button directly from your browser will load the DOM again, so technically there's no way to prevent the refresh from this action.
Late response, I know, but you can always try this (confirmed working in IE):
target = document.activeElement;
alert(target.href);
Just showing you that you can grab the active element and then just parse the href to figure out what is happening.
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