简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM