javascript 关闭弹出窗口后自动刷新父窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3381234/
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-10-25 01:01:53  来源:igfitidea点击:

Auto refresh parent window after closing popup

javascripthtmlforms

提问by maas

I am having 2 pop up screens in my (Main) jsp.

我的(主)jsp 中有 2 个弹出屏幕。

In the first pop-up the user will update the required information(Update) and after submitting the info, a new pop up will be shown that shows the modifications(View).

在第一个弹出窗口中,用户将更新所需的信息(更新),提交信息后,将显示一个新的弹出窗口,显示修改(查看)。

I would like to refresh the Main page when the user clicks on the close "X" in the view page.

当用户单击视图页面中的关闭“X”时,我想刷新主页面。

I tried to use some scripts like the following in the view page, but it did not work:

我尝试在视图页面中使用一些类似以下的脚本,但它不起作用:

<script language="JavaScript">
function refreshParent() {
  window.opener.location.href = window.opener.location.href;

   if (window.opener.progressWindow)

   {
    window.opener.progressWindow.close()
   }
   window.close();
  }
</script>

回答by Sarfraz

Try putting this javascript code in your popup window:

尝试将此 javascript 代码放在弹出窗口中:

window.onunload = function(){
  window.opener.location.reload();
};

回答by Dee_wab

 function ref_and_close()
  {         
    opener.location.reload();   
    self.close();       
  }

//just call the function 
    ref_and_close();