Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent bootstrap 3 modal from closing when user refreshes the entire page

How can I prevent bootstrap 3 modal from closing when the user refreshes the page? I want the user to close the modal only using the CLOSE button, nothing else.

like image 433
Majase Avatar asked Dec 24 '22 04:12

Majase


1 Answers

That can't be done. When the user refreshes the page the modal will be gone.

Your only option would be to re-open the modal on page refresh. To do that you would have to store some variable in a cookie or localStorage to tell you that they haven't yet closed the modal.

Then you could do something like this:

$(function() {
    if(cookieOrLocalStorageVariable) {
       $('#myModal').modal(options);
    }
});

The cookieOrLocalStorageVariable would need to be defined by you and should be set once the modal is shown.

like image 57
Robban Avatar answered Jan 11 '23 23:01

Robban