Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 关闭弹出窗口后刷新父窗口_Javascript_Popup_Window_Parent - Fatal编程技术网

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

Javascript 关闭弹出窗口后刷新父窗口,javascript,popup,window,parent,Javascript,Popup,Window,Parent,我正在创建一个指向hello.html的弹出窗口。我希望在关闭弹出窗口(hello.html)时重新加载原始(父页面)。我似乎不能让它工作,但我很接近。以下是我到目前为止在主页和hello.html页面上的代码 <!DOCTYPE html> <html> <head> <script type="text/javascript"> function open_win() { window.open("hello.html","_blank","t

我正在创建一个指向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>

函数open_win()
{
window.open(“hello.html”,“_blank”,“toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizeable=no,copyhistory=yes,width=400,height=400”);
}
函数refreshParent(){
window.opener.location.href=window.opener.location.href;
if(window.opener.hello.html)
{
window.opener.hello.html.close()
}
window.close();
}
var d=新日期();
文件编写(d);
这是hello.html

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

Hello

</body>
</html>

你好
订阅子窗口中的,并从子窗口调用父窗口,通知它正在关闭

编辑添加了一个代码示例

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

这样做,在创建弹出式监视器后,每隔一段时间显示其“关闭”状态属性。但这会添加到父文档中:

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

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

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

/onunload事件将在关闭弹出窗口时触发,window.opener.location.reload()将重新加载源(父)窗口。//

在弹出关闭函数的单击事件上尝试

window.opener.location.reload(true);

如果使用
window.open
功能弹出一个新窗口,这段代码也可以工作

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

将此脚本放在弹出窗口的标题中:

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

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

当您关闭弹出窗口时,这将重新加载父窗口。

请检查这一点:可能对某人有帮助这是一个非常糟糕的解决方案,但它是在Chrome 55.0.2883.87中唯一对我有效的解决方案。所有其他方法都可以在onclick事件中正常工作,这让我相信Chrome将此限制为仅限于用户启动的操作,类似于调整窗口大小和移动窗口。