我正在尝试使用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();
}
});发布于 2015-09-30 03:08:20
这是一个iframe,所以您需要使用window.parent (see the MDN documentation here)而不是window.opener。这不是一个新的窗口,而是一个框架,所以没有开启器。
请注意,frame和parent的域必须匹配,否则调用将由于跨域安全限制而失败。
下面的代码示例将输出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>
https://stackoverflow.com/questions/32851806
复制相似问题