Prevent 3 loading by modal closing when user refreshes entire page

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

+4
source share
3 answers

It's impossible. When the user refreshes the page, the modality disappears.

The only option would be to reopen the modal page refresh. To do this, you will need to save some variable in a cookie or localStorage to inform you that they have not closed the modal yet.

- :

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

cookieOrLocalStorageVariable .

+8

flag, isModalOpen

function openModal() {
    $('#myModal').modal('show');
    localStorage.setItem('isModalOpen', true);
};

function closeModal() {
    $('#myModal').modal('hide');
    localStorage.setItem('isModalOpen',false);
};

if(localStorage.getItem('isModalOpen')) {
    openModal();
}
+1

you cannot do this. You must save the value in localstorage / cookie / session. You must reopen the modal version using the value that you store in local storage / cookie / session. I agree with durga answer.I think this is the best answer.

+1
source

All Articles