Constantin.FF Constantin.FF - 1 year ago 767
jQuery Question

Close Bootstrap modal from inside iframe

Page which opens Twitter Bootstrap Modal with iframe inside:

<div id="iframeModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="btn btn-danger pull-right" data-dismiss="modal" aria-hidden="true">Close</button>
<div class="clearfix"></div>
<div class="modal-body">
<iframe src="iframe-modal.html"></iframe>
<div class="modal-footer">

And I am looking for a way to close this modal from inside the iframe.
Ex. clicking a link inside the
to close the modal.
What I have tried, but non successful:

$('#iframeModal', window.parent.document).modal('hide');
$('#iframeModal', top.document).modal('hide');

Answer Source

You can always create a globally accessible function which closes the Bootstrap modal window.


window.closeModal = function(){

Then from the iframe, call it using:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download