0

I have a requirement where when we close the tab or close the browser I need to perform some processes. When user will close the tab, there should be no popup getting displayed. I should be able to directly trigger the Leave button of the popup. The code which I am using sometimes work and sometimes not. Is it possible to close the tab or browser without popup or the popup is mandatory. Please advise. Below is my code :-

Without Popup(sometimes work and sometimes not)

window.onbeforeunload = function() {
                             //debugger;
                             perform();
                         };

//With this i get a popup which I don't want

window.addEventListener("beforeunload", function (e) {
                        perform();
                          (e || window.event).returnValue = null;
                          return null;
                        });
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sTg
  • 4,313
  • 16
  • 68
  • 115
  • Maybe you are looking for the [`unload` event](https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event)? – Daan Jun 17 '20 at 07:24
  • replace `return null` with `undefined` as said in this answer: https://stackoverflow.com/a/29627642/9496199 – Ramon de Vries Jun 17 '20 at 07:26

0 Answers0