0

Possible Duplicate:
How can I override the OnBeforeUnload dialog and replace it with my own?

Is there a chance to show custom popup (div) when user leave page? I know there are beforeunload event, but it only show default popup. I need an custom popup with form inside it.

Community
  • 1
  • 1
Arthur Halma
  • 3,943
  • 3
  • 23
  • 44

1 Answers1

0

The short answer is no.

You will only be able to display the default popup that the browser provides. It is not possible to display a custom popup such as a <div> as you are requesting, because by the time it is displayed the tab or window would have already closed.

To display a default popup confirm box before the user leaves the page, you should use the following JavaScript code:

window.onbeforeunload = function(e) {
    return 'Are you sure you wish to leave this page?';
};
Charles
  • 4,372
  • 9
  • 41
  • 80
  • It is possible to display div just before page leave using mouse tracking. But it's not easy and it's not 100% success rate. Research keyword: `exit-intent` – ViliusL Feb 13 '20 at 10:58