javascript 关闭弹出窗口后重新加载父页面

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

Reload parent page after closing popup window

javascriptpopupwindow

提问by John Doe

I am trying to have the user sign in through a popup window. When they click the link to the popup window which is a php variable they can sign in. When the window closes I want it to reload the page they were originally on (the parent page).

我试图让用户通过弹出窗口登录。当他们点击弹出窗口的链接时,他们可以登录。当窗口关闭时,我希望它重新加载他们原来所在的页面(父页面)。

Here is the code on the signin.php page...

这是 signin.php 页面上的代码...

<body onunload="opener.location=('')">

But all this does is make the sign in page become the page the user was on. I think I need to put something in the parentheses, but I can't figure out what goes there.

但所有这些都是使登录页面成为用户所在的页面。我想我需要在括号里放一些东西,但我不知道那里有什么。

回答by Chris Baker

To reload a page, you can set the location property as the current value, like this:

要重新加载页面,您可以将 location 属性设置为当前值,如下所示:

window.location = window.location;

So for your case, you would use, literally:

因此,对于您的情况,您可以从字面上使用:

onunload="window.opener.location = window.opener.location;"

You can also use the reloadmethod of the locationobject:

也可以使用对象的reload方法location

onunload="window.opener.location.reload();"

This is the preferred method.

这是首选方法。

Also, please refer to the accepted answer for your previous question: Refreshing Parent window after closing popup

另外,请参阅上一个问题的已接受答案:关闭弹出窗口后刷新父窗口

Documentation

文档

回答by gnanasekar

echo '<script>window.opener.location.reload()</script>';
echo '<script>self.close()</script>';

It works well in all browsers.

它适用于所有浏览器。