[英]dialog modal window not closing when called from child page
我正在尝试使用jQuery UI对话框作为弹出窗口,并且我想将另一个aspx页面作为主体放置到Jquery UI对话框中。 在这里,我不想使用Jquery按钮选项。 在子页面上,我放置了应该关闭模态窗口并刷新父页面的按钮。 下面是我一直在尝试实现的代码,但是由于某种原因我收到了js错误消息。 我在这里想念什么吗?
父页面:aspx页面
<div>
<div id="dialog" title="This is Pop up ">
<div class="modal">
<div class="modal-body">
<iframe style="width: 100%; height: 100%;" src="childPage.aspx" runat="server" frameborder="0"></iframe>
</div>
</div>
</div>
<input type="button" value="open" id="OpenDialog"/>
</div>
jQuery代码:父页面
$(function () {
var dialog
dialog = $("#dialog").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
});
$("#OpenDialog").button().on("click", function () {
dialog.dialog("open");
});
});
子页面:
<input type="button" id="btnCloseChildPageRefreshParent" value="Close and Refresh Parent Page" />
子页面Js代码:
$(function () {
$('#btnCloseChildPageRefreshParent').on('click', function () {
refreshParent();
open(location, '_self').close();
});
function refreshParent() {
window.opener.location.reload();
}
});
这是一个iframe
因此您需要使用window.parent
( 请参见此处的MDN文档 )而不是window.opener
。 它不是一个新窗口,而是一个框架,因此没有打开器。
请注意,框架的域和父域必须匹配,否则由于跨域安全性限制,调用将失败。
下面的代码示例将打印出window.opener
的值以及对window.parent.location.reload
的调用所生成的错误,以进行说明。
function log (o) { var el = document.createElement('div'); el.innerHTML = o; document.body.appendChild(el); } document.getElementById('button').onclick = function () { //This line could be used if the domain of the frame and parent match //window.parent.location.reload(); log('window.opener is: ' + window.opener); try { window.parent.location.reload(); } catch (e) { log('Attempted to call window.parent.location.reload(): ' + e); } }
<button id="button">Reload Parent</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.