How to close a modal only by the buttons?

2

The title is already high explanatory. But I'd like to know how I close a modal by just the close button and the "x" of the window, not allowing the user to click on the black background around the pop up window to close.

HTML:

<!--Buttontriggermodal--><buttontype="button" id="mymodal" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </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>

link

    
asked by anonymous 10.02.2017 / 20:05

1 answer

3

Use the backdrop option with data-backdrop="static" . As seen in official documentation , this option causes the modal window to not close with click , with the buttons only.

<!-- Button trigger modal -->
<button type="button" id="mymodal" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" data-backdrop="static">
  Launch demo modal
</button>

Example: link

    
10.02.2017 / 20:09