Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>     <div class="modal-body">         <iframe src="iframe-modal.html"></iframe>      </div>     <div class="modal-footer">     </div> </div> 

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

$('#iframeModal', window.parent.document).modal('hide'); $('#iframeModal', top.document).modal('hide'); $('#iframeModal').modal('hide'); 
like image 279
Constantin.FF Avatar asked Mar 06 '13 14:03

Constantin.FF


1 Answers

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

eg.

window.closeModal = function(){     $('#iframeModal').modal('hide'); }; 

Then from the iframe, call it using:

window.parent.closeModal(); 
like image 167
Dzulqarnain Nasir Avatar answered Oct 10 '22 22:10

Dzulqarnain Nasir