I am looking for a way to make this modal persistent once it show up. As it's presented here, the user can close it with a simple click outside of the div.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Activate Modal with JavaScript</h2>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(window).load(function(){
$('#myModal').modal('show');
});
});
</script>
</body>
</html>
Is there a way to block this modal so it's still there even with a mouse click outside of it?
Something like this ought to get you started. You can fiddle around with different values like color, timing, etc.
To "persist the modal" (aka prevent hiding) hook into the hide event and return false to prevent hiding.
Here's a full code example.
Edit: To hide the modal, redefine the response to the hide event before calling
hide()
. The following function does this. You can execute the function whenever is appropriate (e.g. on a button click).Is code-only answer acceptable?
More examples please see here http://nakupanda.github.io/bootstrap3-dialog/