js prevent modal to close code example

Example 1: javascript modal close

$('#closemodal').click(function() {
    $('#modalwindow').modal('hide');
});

Example 2: disable close from screen modal popup

<!-- opening with html, the key is the data-backdrop="static" attribute -->
<button data-target="#myModal" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    Launch demo modal
 </button>
 
<script>
//Opening with JS:
$('#myModal').modal({backdrop: 'static', keyboard: false})  
</script>

Tags:

Html Example