Question: 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

Answer: 
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.*