Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close all active bootstrap modals on session timeout?

I need to make a call when the user is idle and passes the session time out that will close all Bootstrap modals. The modals being active are dependent on what the user is doing at the time so I would like to do something that's is all encompassing.

I tried:

$('.modal').modal('toggle'); 

When the time out occurs but my modals are still there.

like image 624
jeff werner Avatar asked Jul 31 '13 18:07

jeff werner


People also ask

How do you force close modals?

Answer: Use the modal('hide') Method You can simply use the modal('hide') method to hide or close the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('show') and modal('toggle') .

How do I stop Bootstrap modal close Onclick outside?

When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.

How do you close a modal class?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.


2 Answers

Use the following code:

$('.modal').modal('hide'); 

Also if you would like to do something if the modal is hidden then you can do this:

$('.modal').on('hidden', function () {   // write your code }); 
like image 145
S. Rasel Avatar answered Sep 27 '22 18:09

S. Rasel


The correct answer is missing something vital.

$('.modal').modal('hide') // closes all active pop ups. $('.modal-backdrop').remove() // removes the grey overlay. 

The second line is vital if you want the users to use the page as normal.

like image 34
Tom McDonough Avatar answered Sep 27 '22 19:09

Tom McDonough