Dilip Oganiya
Dilip Oganiya

Reputation: 1554

How to display popup with custom HTML on browser close tab using JavaScript/Jquery ? I have custom HTML popup

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

Upvotes: 2

Views: 2842

Answers (2)

G. Pizzo
G. Pizzo

Reputation: 11

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.

Upvotes: 0

Lesleyvdp
Lesleyvdp

Reputation: 323

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

Upvotes: 1

Related Questions