irfanhans irfanhans - 5 months ago 13
Javascript Question

modal prevent click outside not work using javascript

i have a try with my code but not working , modal still click using mouse, here some code

My Modal :

<!-- modal -->

<div id="my-modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="border-bottom: 1px solid rgba(229, 229, 229, 0); background: #FF5722; color: #fff;">
<h4 class="modal-title"><i class="fa fa-exclamation-triangle"></i> Danger</h4>
</div>
<div class="modal-body" style="background: #FF5722; color: #fff;">
Hello World!
</div>
<div class="modal-footer" style="background: #FF5722; border-top: 1px solid rgba(229, 229, 229, 0);">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>




and javascript :

<script type="text/javascript">
$(window).load(function(){
$('#my-modal').modal('show');
$('#my-modal').modal({
backdrop : 'static',
keyboard : false
})
});



Answer

Change this:

$('#my-modal').modal('show');
$('#my-modal').modal({
  backdrop : 'static',
  keyboard : false
})

...to this:

$('#my-modal').modal({
  backdrop : 'static',
  keyboard : false
});
$('#my-modal').modal('show');

You could even omit $('#my-modal').modal('show'); entirely.