javascript 关闭弹出窗口后刷新父窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4571860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh parent window after closing a popup window
提问by user246392
I am opening a popup window from X.jsp and the popup is represented by Y.jsp. The second jsp has a button. What I would like to do is to refresh the parent page (the one that launches the popup) once this button is hit. The Save button below will call a method in the backing bean "copyScriptForVersion" and I close the popup on button click. How could I also refresh the parent window after closing the popup?
我正在从 X.jsp 打开一个弹出窗口,该弹出窗口由 Y.jsp 表示。第二个jsp有一个按钮。我想要做的是在点击此按钮后刷新父页面(启动弹出窗口的页面)。下面的“保存”按钮将调用支持 bean“copyScriptForVersion”中的一个方法,并在单击按钮时关闭弹出窗口。关闭弹出窗口后如何刷新父窗口?
<h:commandButton type="submit" value="Save" action="#{copyScriptForVersion.SaveAction}" onclick="window.close()"/>
I tried adding window.opener.reload() like this onclick="window.close(); window.opener.reload();", but that didn't work.
我尝试添加 window.opener.reload() 像这样 onclick="window.close(); window.opener.reload();",但这没有用。
I also tried adding the following body onUnLoad="window.opener.location.reload(1);">
我还尝试添加以下主体 onUnLoad="window.opener.location.reload(1);">
But, I got "window.opener.location is null or not an object" error.
但是,我收到“window.opener.location 为空或不是对象”错误。
采纳答案by DVK
First of all, you should do window.close()as a LAST action in the onClick handler. Otherwise, it's possible it will never get executed.
首先,您应该window.close()在 onClick 处理程序中执行LAST 操作。否则,它可能永远不会被执行。
Second, if reload() doesn't work, try:
其次,如果 reload() 不起作用,请尝试:
window.opener.location.href = window.opener.location.href; window.close();
Please note that this may cause problems if the parent page was produced as a result of POSTing a form.
请注意,如果由于发布表单而生成父页面,这可能会导致问题。
回答by Ankit Balyan
Try this it may help other as well,,
试试这个它也可以帮助其他人,,
`new = window.open(url);
new.focus();
check = setInterval(function() {
if (new.closed) {
window.location.reload(true)
}}, 1000);`

