When using Twitter Bootstrap 3, Is there anyway to know when the modal is closed by a backdrop click ?
To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.
When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.
How check modal is open or not in jQuery? You can simply use the modal('show') method to show or open the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('hide') and modal('toggle') .
The easiest and and functional way in every case-
$(document).click(function (e) {
setTimeout(function(){
if (!$('body').hasClass('modal-open')) {
$("#myModal iframe").attr("src", $("#myModal iframe").attr("src"));
}
},1000);
});
I can't find any built in function to check what you want.
The only "hacky" way I found is to check the click/keyup event of the document and if the modal is opened call your callback.
Code:
$(document).keyup(function (e) {
if (e.which == 27 && $('body').hasClass('modal-open')) {
console.log('esc')
}
})
$(document).click(function (e) {
if (e.target === $('.modal-scrollable')[0] && $('body').hasClass('modal-open')) {
console.log('click')
}
})
Demo: http://jsfiddle.net/IrvinDominin/7nnUq/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With