Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap modal closes on clicking anywhere

I am trying to use a simple bootstrap modal, but it closes on clicking it anywhere, and not on clicking on the close button only. I haven't used any other extra javascript or jquery code on the page. Here's the link where my code is. The modal trigger button is on the bottom.

http://aijaz.co/angloamerican/

This is the default code I am using.

<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-large">Launch demo modal</a>


<div id="myModal" class="modal fade">
    <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>
                <h4 class="modal-title">Confirmation</h4>
            </div>
            <div class="modal-body">
                <p>Do you want to save changes you made to document before closing?</p>
                <p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>
like image 523
Kristie Matthew Avatar asked Jan 09 '23 02:01

Kristie Matthew


2 Answers

Add data-backdrop="static" as an attribute of myModal. See http://getbootstrap.com/javascript/#modals-options for more details.

like image 178
mmccaff Avatar answered Jan 10 '23 16:01

mmccaff


Try to put data-backdrop="true" on your #myModal element.

Like this:

<div id="myModal" class="modal fade" data-backdrop="true">
like image 44
user2581193 Avatar answered Jan 10 '23 17:01

user2581193