Prevent Modal from Closing when Clicking Outside - HTML CSS Bootstrap

HTML CSS examples for Bootstrap:Modal

Description

Prevent Modal from Closing when Clicking Outside

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
 <head> 
  <title>Disable Closing of Bootstrap Modal on Click of Dark Area</title> 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"> 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
  <script type="text/javascript">
$(document).ready(function(){
  $('.launch-modal').click(function(){
    $('#myModal').modal({
      backdrop: 'static'
    });<!--  w w w  .ja  v  a  2  s  . co  m-->
  }); 
});
</script> 
 </head> 
 <body> 
  <div> 
   <input type="button" class="btn btn-lg btn-primary launch-modal" value="Launch Demo Modal"> 
   <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"></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> 
       <p class="text-info"><small><strong>Note:</strong> This is a test. This is a test. This is a test.This is a test. This is a test. This is a test.This is a test. This is a test. This is a test..</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> 
  </div>   
 </body>
</html>

Related Tutorials