I recently added a JavaScript dialog into my page, which will let the user confirm if they really want to leave the page. However, I also have buttons navigating to other pages on my page, and I don't want the leaving site confirm dialog to show up when users click these buttons.
I haven't really found out a way on how to do this, partly because I'm new to HTML and JavaScript.
Below is my code I'm using for the confirm dialog, which I also got from here on Stack Overflow.
window.onbeforeunload = function (e) {
e = e || window.event;
if (e) { // For IE and Firefox prior to version 4
e.returnValue = 'Any string';
}
return 'Any string'; // For Safari
};