I want to make a popup which does not allows user to close browser until popup closes

2.2k Views Asked by At

I want to make popup which freezes the browser until the popup is closed. But I am stuck at a point since on closing the browser, it is asking the user to stay or leave but when a user clicks on leave it shuts down. I instead want a that when a user clicks the leave option it either reload the site or do nothing, also on doing the same for second time Chrome is giving alert to prevent any additional dialogue which I want to disable or it should do nothing. Until the popup is closed. So at last users should not be able to close their browser from a closing button of browser or by going back or replacing the URL. It should freeze until the requirement of the popup is fulfilled. Thank you and please help.

2

There are 2 best solutions below

4
Spitzbueb On

You can't force the users to stay on your site as the browser doesn't allow this (think of a malicious site forcing you to stay there). Your approach is probably the best you can do. Show a dialog that says something like. "Please wait while exiting..." or similar.

If you want to hide the "Block additional dialogs from this page" thing you can create your own dialog. Just a div with position: fixed and display: none and then onBeforeUnload show it with display: block. Here is more on that: Stackoverflow.com

4
Hitarthi Panchal On

In that case you can use bootstrap popup: like this:

https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&stacked=h

and on the click event on close button you can add new alert or some other popup.. and closing this type of popup box cannot reflect other data..

It might helps you.!