javascript - 从 iframe 内部关闭 Bootstrap 模式

标签 javascript jquery twitter-bootstrap parent-child

打开带有 iframe 的 Twitter Bootstrap Modal 的页面:

<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 内部关闭此模式的方法。 前任。单击 iframe-modal.html 中的链接以关闭模式。 我尝试过但没有成功:

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

最佳答案

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

例如。

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

然后从 iframe 调用它:

window.parent.closeModal();

关于javascript - 从 iframe 内部关闭 Bootstrap 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15249678/

相关文章:

html - 为什么手机上的 <ul> 类 "list-inline"<li> 不在同一高度?

javascript - 我将如何执行 for 循环,等待每个循环的函数完成?

javascript - Angular 5 httpClient 和 promise

javascript - 需要帮助在验证器中添加值

javascript - Backbone : Creating multiple models in a collection from a nested object

Jquery UI 工具提示。设置超时并设置悬停事件。鼠标悬停时卡住工具提示

jquery - 在运行时将submitHandler添加到jQuery validate()

angularjs - 如何禁用 ui.bootstrap.pagination

jquery - 如何使用 jQuery 更改和更改 CSS

javascript - Angular Bootstrap DatePicker UTC 错误输出