In Twitter bootstrap, looking at the modals documentation. I wasn't able to figure out if there is a way to listen to the close event of the modal and execute a function.
e.g. lets take this modal as an example:
<div class="modal-header">
<button type="button" class="close close_link" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<a href="#" class="btn close_link" data-dismiss="modal">Close</a>
</div>
The X button on top and the close button on bottom can both hide/close the modal because of data-dismiss="modal"
. So I wonder, if I could somehow listen to that?
Alternatively I could do it manually like this, I guess...
$("#salesitems_modal").load(url, data, function() {
$(this).modal('show');
$(this).find(".close_link").click(modal_closing);
});
What do you think?
Updated for Bootstrap 3 and 4
Bootstrap 3 and Bootstrap 4 docs refer two events you can use.
And provide an example on how to use them:
Legacy Bootstrap 2.3.2 answer
Bootstrap's documentation refers two events you can use.
And provides an example on how to use them:
If your modal div is dynamically added then use( For bootstrap 3)
This will work for non-dynamic content also.
There are two pair of modal events, one is "show" and "shown", the other is "hide" and "hidden". As you can see from the name, hide event fires when modal is about the be close, such as clicking on the cross on the top-right corner or close button or so on. While hidden is fired after the modal is actually close. You can test these events your self. For exampel:
And, as for your question, I think you should listen to the 'hide' event of your modal.