Possibly related to How to open mailto link in Chrome with Window.open without creating a new tab?
Hi all. I have a form page where i\'ve put a window.onbeforeunload co
Another option, also a bit hacky but a bit more generic way to make the beforeunload ignore certain types of links:
In the beforeunload, inspect the link that caused the beforeunload, and if it is not a http or https link, don't bother the user.
Unfortunately it is not easy to inspect the link that caused the beforeunload, so this is where it gets a little hacky with an onclick handler and global variable.
var lastClicked = null;
window.onclick = function(e){
e = e || window.event;
lastClicked = e.target
}
window.onbeforeunload = function(e){
if (changed && lastClicked && lastClicked.href
&& lastClicked.href.substring(0,4) == 'http')
return "You have unsaved changes";
}
Edit: Almost forgot, this answer comes from here: https://stackoverflow.com/a/12065766/421243