Javascript 关闭子弹出窗口并刷新父页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5139657/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:48:44 来源:igfitidea点击:
Closing child pop-up and refreshing the parent page
提问by cool2cool
I am trying to achieve the following.
我正在努力实现以下目标。
- A link on a parent page will open a new child pop-up.
- In the child pop-up, the user enters some data and clicks “Save”.
- Data will be saved to database and the pop-up will be closed. The parent window would be refreshed, and the data entered in the child pop-up would be displayed in the parent page.
- 父页面上的链接将打开一个新的子弹出窗口。
- 在子弹出窗口中,用户输入一些数据并单击“保存”。
- 数据将被保存到数据库并关闭弹出窗口。父窗口将被刷新,在子弹出窗口中输入的数据将显示在父页面中。
How can this (closing a child pop-up and refreshing the parent page) be done in Javascript?
如何在 Javascript 中完成(关闭子弹出窗口并刷新父页面)?
回答by derekcohen
In the pop-up window:
在弹出窗口中:
<script type="text/javascript">
function proceed(){
opener.location.reload(true);
self.close();
}
</script>
<form onsubmit="proceed()">
...
</form>
回答by Delan Azabani
In the popup's code for closing/reloading:
在用于关闭/重新加载的弹出窗口代码中:
opener.location.reload();
close();
回答by erickb
parent.html
父.html
<a href="#" onclick='window.open("child.html","_blank","height=100,width=100,
status=yes,toolbar=no,menubar=no,location=no");return false'>pop up</a>
child.html
孩子.html
<p>child window</p>
<script>
window.onload = function(){
window.opener.location.reload(true);
window.close();
}();
</script>