从iframe内部关闭Bootstrap模式 [英] Close Bootstrap modal from inside iframe

查看:81
本文介绍了从iframe内部关闭Bootstrap模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用iframe打开Twitter Bootstrap Modal的页面:

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>

我正在寻找一种从iframe内部关闭此模态的方法。
Ex。单击 iframe-modal.html 内的链接以关闭模式。
我尝试过但不成功:

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');


推荐答案

您始终可以创建一个全局可访问的函数来关闭Bootstrap模态窗口。

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

例如。

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

然后从iframe中调用它:

Then from the iframe, call it using:

window.parent.closeModal();

这篇关于从iframe内部关闭Bootstrap模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆