I am using the following code to catch the moment when a user tries to close or back a page:
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "Are you sure?";
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
However, I have a few buttons and links on the page that also triggers the event when clicked, I wonder if there is any way to avoid listening the event when clicking anchor tags and buttons but only when closing or back?
Any help would be appreciated.