关闭弹出后刷新父窗口(Refreshing Parent window after closing

2019-06-26 04:22发布

我创建进入的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>

这里是hello.html的...

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

Hello

</body>
</html>

Answer 1:

订阅卸载事件中的子窗口,并从子窗口调用父窗口,通知它关闭!

编辑加了代码示例...

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()
};


Answer 2:

像这样做,创建弹出监控其“关闭”状态属性中的时间间隔后。 但是,这是父文档中加入:

var pop = window.open("page.html", "popup",
            "width=800,height=500,scrollbars=0,title='popup'");
    pop.focus();

    var monitor = setInterval(function() {

        if (pop.closed) {
            document.location.reaload()
        }

    }, 1000);


Answer 3:

尝试把这段JavaScript代码在你的弹出窗口:

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

/ 当您关闭弹出窗口onunload事件将触发,和window.opener.location.reload()将刷新源(父)窗口。 /



Answer 4:

在弹出关闭功能的单击事件试试...

window.opener.location.reload(true);


Answer 5:

如果一个新的窗口与弹出这段代码的工作原理以及window.open功能。

setTimeout(function () { window.opener.location.reload(true); window.close();}, 3000);


Answer 6:

将这个脚本在弹出窗口的标题:

<script type='text/javascript'>
window.onunload = function(){
window.opener.location.reload();}
</script>

当您关闭弹出这将刷新父窗口。



文章来源: Refreshing Parent window after closing popup