2

I want to display custom HTML Popup when user close web browser using Jquery/Javascript.I have googled it but not found any solution to achieve that.

Please help me. I am stuck since many days !!

Thanks

Dilip Oganiya
  • 1,504
  • 12
  • 20

2 Answers2

1

Assuming you want to prevent users from just closing the tab, you can provide them an alert if you use the following:

window.onbeforeunload = function (e) {
    e = e || window.event;

    // For IE and Firefox prior to version 4
    if (e) {
        e.returnValue = 'Sure?';
    }

    // For Safari
    return 'Sure?';
};

Original answer from: https://stackoverflow.com/a/10311375/6524598

Lesleyvdp
  • 313
  • 2
  • 14
0

Unfortunately, using the only available methods "onbeforeunload" or "unload" it is not possible to customize the popup displayed when the browser or browser tab is closed, because for the two methods you need to return a string.

Infact you cannot use your own dialog boxes (or jQueryUI modal dialogs) to override beforeunload method.

G. Pizzo
  • 11
  • 2
  • Any other option ? – Dilip Oganiya Oct 11 '18 at 13:08
  • You will have to show the html popup in another context, not connected to the closing event of the browser. You could connect the popup to mouse / keyboard events if the user performs a particular action that makes him leave the current page, for example if you click on a link to go to another page / website... It depends on your final purpose. or use an ajax call to mark the browser close event, and act accordingly by creating logs. – G. Pizzo Oct 11 '18 at 13:22