从 child window 调用操作,关闭 child window 并重新加载 parent 页面

Call action from child window, close the child window and reload the parent page

我有一个来自 parent window 的 link,它打开了一个 child window。单击 child window 中的保存按钮时,我想调用 struts 操作并关闭 child window。然后重新加载 parent window.

function closeChildWindow(){
document.forms[0].action="/rms/action/linkSourceList";
document.forms[0].submit();
var originalSource = document.getElementById("originalSource").value;
opener.location.href = '../action/editSource?source_id='+originalSource;
}

我在childwindow中使用了上面的代码。此代码重新加载 parent window,但不从 child window 调用操作。谁能建议我解决方案??提前致谢...:)

如果你使用一些 JavaScript 库,事情会容易得多。

我会在jQuery中举个例子:

function submitAndCloseChildWindow(){
    var data = /* get form data here */;
    $.ajax({
        url: "/rms/action/linkSourceList",
        data: data,
        method: "POST"
    }).done(function() {
        opener.location.href = '../action/editSource?source_id=' + $("#originalSource").val();
        window.close();
    });
}

这将使您的 window 在失败时保持打开状态,并允许您处理任何预期的错误。另外,如果请求仍然没有通过,请咨询控制台。