I have window.onbeforeunload triggering properly. It\'s displaying a confirmation box to ensure the user knows they are navigating (closing) the window and that any unsaved
var link_was_clicked = false; document.addEventListener("click", function(e) { if (e.target.nodeName.toLowerCase() === 'a') { link_was_clicked = true; } }, true); window.onbeforeunload = function() { if(link_was_clicked) { link_was_clicked = false; return; } //other code here }