HOW TO STOP CLOSING OF BOOTSTRAP MODAL POPUP OUTSIDE CLICK

Pawan Shukla

Total Post:38

Points:274
Posted by  Pawan Shukla
 12553  View(s)
Ratings:
Rate this:
I have a bootstrap modal popup in my application, it closes when i click on outside of modal popup, I only want that modal popup closes on click of cross button and close button

below is my code:

<div class="container">

    <br />

    <br />

    <button class="btn btn-primary" id="launchmodal" data-toggle="modal" data-target="#myModal">

        Launch demo modal

    </button>

</div>

 

<!-- Modal -->

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">

        <div class="modal-content">

            <div class="modal-header">

                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</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>

Here is my javascript code:

<script>

    $(document).ready(function () {

        $('#launchmodal').click(function () {

            $('#myModal').modal({

                keyboard: false

            })

        });

    });

 </script>

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: How to stop closing of Bootstrap modal popup outside click

    Hi pawan shukla

    i'm solve your problem you can use this code

    <script>

        $(document).ready(function () {

            $('#launchmodal').click(function () {

                $('#myModal').modal({

                    backdrop: 'static',

                    keyboard: false,

                })

            });

     

        });

    </script>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!