关闭弹出窗口后刷新父窗口

Joh*_*Doe 9 javascript window popup parent

我正在创建一个转到hello.html的弹出窗口.当我关闭弹出窗口(hello.html)时,我希望我的原始(父页面)重新加载.我似乎无法让它工作,但我很接近.这是我到目前为止主页和hello.html页面的代码....

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function open_win()
{
window.open("hello.html","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
}
</script>


<script language="JavaScript">

function refreshParent() {
  window.opener.location.href = window.opener.location.href;

  if (window.opener.hello.html)

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


</head>

<body>

<script type="text/javascript">

var d=new Date();
document.write(d);

</script>

<form>
<input type="button" value="Open Window" onclick="open_win()">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是hello.html ......

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
</script>
</head>
<body>

Hello

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Spl*_*ity 11

在子窗口中订阅unload事件并从子窗口调用父窗口以通知它正在关闭!

编辑添加了代码示例...

function popupClosing() {
  alert('About to refresh');
  window.location.href = window.location.href;
}

var w = window.open("hello.html","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
w.onunload = function () {
  window.parent.popupClosing()
};
Run Code Online (Sandbox Code Playgroud)