【发布时间】:2014-07-20 00:29:41
【问题描述】:
我正在尝试关闭以下列方式打开的窗口:
var myWindow;
function openLink(){
myWindow = window.open("http://mydir.com", "MsgWindow", "width=600, height=400, left=250, top=200");
}
这会在某种弹出窗口中打开一个窗口 (Here you can see how it works)
我想要做的是当我的 ajax 调用完成时(在打开的窗口中)关闭窗口。我正在尝试这个:
$.ajax ({
url: "php/copia.php",
type: "post",
data: {"params": result,
"dirDest":dirDest},
success: function(response) {
$.mobile.loading('hide');
window.parent.postMessage('Close popup', '*');//I am trying to send a message to the parent window but it doesnt work
}
});
在打开新窗口的窗口中,我有以下内容:
$( document ).ready(window.addEventListener("message", closePopup, false));
function closePopup(event) {
myWindow.close();
}
【问题讨论】:
-
我认为你需要 window.opener 而不是 window.parent 见stackoverflow.com/questions/11313045/…
标签: javascript jquery html ajax