How to intercept Bootstrap modal from closing

Posted By : Monu Thakur | 27-Jun-2016

By default, if you click outside of the modal box window i.e. on the backdrop or dark area it will close and evaporate.  when you within unconditional, press the Esc key on the keyboard it happen. But you can intercept this from happening by setting the modal's backdrop option to static and keyboard option to false, like this:

Befor writting this code which is given below you have to include this library files in head tag:

<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>


$(document).ready(function(){
    $('.launch-modalBox').click(function(){
        $('#myModalBox').modal({
            backdrop: 'static'
        });
    }); 
});
</script>


<div class="modal-example">
    <!-- Button HTML (to Trigger Modal) -->
    <input type="button" class="btn btn-lg btn-primary launch-modalBox" value="Launch Demo My Modal Box">
    
    <!-- Modal HTML -->
    <div id="myModalBox" 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>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</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</button>
                </div>
            </div>
        </div>
    </div>
</div>



 

THANKS

About Author

Author Image
Monu Thakur

Monu is an experienced Frontend Developer, having good knowledge of Photoshop, illustrator, HTML5, CSS3, Less, Sass, Javascript, Jquery, Angular 4, Angular 4 theme integration.

Request for Proposal

Name is required

Comment is required

Sending message..