简体   繁体   中英

Is there any way to prevent the browser closing after clicking on the “Close” button

My requirement is as follows:

When the User clicks the close button on the browser in a page, the customized popup window will appear. I had designed the popup window and I can open that window with the following code:

 window.onbeforeunload = function (e) {
            openwindow(200, 100, 'Close.aspx');
        };

But my ultimate requirement is that the main parent window should not be closed after clicking any buttons on the popup window. I don't want the browser's default alert return message window and I am displaying the popup window here instead of browser's default alert window. Is there way to stop the browser closing..?

Due to security reasons this is not possible!

You can show a confirmation dialog using onbeforeunload (see eg here for how to do it), giving the user the choice to not leave the page after all. But you can't prevent the closing against the user's will.

window.onbeforeunload = function(e) {
    return 'Dialog text here.';
};

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