I have this JSFiddle.
I have Bootstrap Modals as in this example, and I need to intercept their Open/Show event. But none of the suggestions mentioned in this thread work for me. Am I missing something?
I tried the following:
// Listener - Show Event Interception
// NONE OF THE FOLLOWING WORK
$('#modal').on('shown.bs.modal', function (e) {
alert('Modal opened 1');
});
$('#modal').on('shown', function (e) {
alert('Modal opened 2');
});
$(window).on('shown.bs.modal', function() {
alert('Modal opened 3');
});
My Modal looks like this (opened with $('#modal').show();
):
<div class="modal modal-dialog" id="modal" tabindex="-1" role="dialog" aria-hidden="true" >
<div class="modal-content" style="margin:0 auto;">
...
</div>
</div>
Update
The immediate problem is that I'm using show()
rather than modal('show')
. However I also tried to intercept using $(document).on('show', function(evt) {..}
and failed.
New approach just to intercept a jQuery show()
event:
$(document).on('show', function(evt) {
if($(evt.target).attr('role') != null && $(evt.target).attr('role') == 'dialog') {
alert('Intercepted Dialog Show');
}
});