Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 modal does not close on outside click

I have created a modal using call,

 $('#myModalContent').modal('show');

html is:

<div class=" modal fade" id="myModalContent" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">


            </div>

        </div>
    </div>
</div>

Problem is when i click outside the modal popup, its doesn't close. (its closes on esc)

like image 486
jsduniya Avatar asked May 21 '14 12:05

jsduniya


People also ask

How do I make Bootstrap modal not close on click 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 by clicking outside?

Modal Header You have two options to close this modal: Click on the "x" or click anywhere outside of the modal!

How can you prevent modal from closing when clicking outside react?

You can prevent closing of modal dialog by setting the beforeClose event argument cancel value to true.

How do you force close modals?

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.

How to stop bootstrap modal from closing on click outside?

The bootstrap modal prevent close on click outside with the use of HTML and Boostrap only. Also, on pressing the escape ('ESC') button of a keyboard, the modal will not close. You can stop closing the modal on mouse click outside of the Bootstrap modal popup.

How do I hide the background of a bootstrap modal?

Answer: Use the Modal's backdrop Option. By default, if you click outside of the Bootstrap modal window i.e. on the backdrop or dark area it will close and disappear.

How do I prevent a modal from crashing when I click?

But you can prevent this from happening by setting the modal's backdrop option to static and keyboard option to false, as shown in the following example:

Is it possible to have multiple modals in Bootstrap?

On the Bootstrap page, it says that multiple modals are not supported. Always try to place a modal's HTML code in a top-level position in your document to avoid other components affecting the modal's appearance and/or functionality.


Video Answer


1 Answers

You can pass options to the modal as :

$('#myModal').modal({
    show:true,
    backdrop:true,
    keyboard:true
})
like image 164
Vishal Kumar Verma Avatar answered Sep 18 '22 03:09

Vishal Kumar Verma