0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
andresmijares
  • 3,658
  • 4
  • 34
  • 40

0 Answers0