javascript 重定向后 window.opener 为空

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

window.opener is null after redirect

javascriptwindow.open

提问by Mike

I am opening a paypal window from the parent with window.open(). After payment and redirecting back to my page (in the popup window), I would like to close the popup and update the parent window URL.

我正在从父母那里打开一个贝宝窗口window.open()。付款并重定向回我的页面(在弹出窗口中)后,我想关闭弹出窗口并更新父窗口 URL。

I found out this works over window.opener.location.

我发现这适用于 window.opener.location。

However the console shows

但是控制台显示

window.opener.location is null

window.opener.location 为空

after redirection because as the child window changes, the popup looses the information about the opener.

重定向后,因为随着子窗口的变化,弹出窗口会丢失有关开启者的信息。

Well great. Now is there any way to get around this? Maybe adding a sort of "listener" to the parent who listens to the URL of the child?

很好。现在有什么办法可以解决这个问题吗?也许向侦听孩子 URL 的父母添加一种“侦听器”?

回答by Wladimir Palant

window.openeris removed whenever you navigate to a different host (for security reasons), there is no way around it. The only option should be doing the payment in a frame if it is possible. The top document needs to stay on the same host.

window.opener每当您导航到不同的主机时都会被删除(出于安全原因),没有办法绕过它。如果可能,唯一的选择应该是在框架中进行付款。顶层文档需要留在同一个主机上。

回答by AmGates

First you can have a timer function in the parent windows to check whether the child window is opened or closed at particular time interval say 100ms or so. If it is closed then you can reload the parent window.

首先,您可以在父窗口中使用计时器功能来检查子窗口是否以特定时间间隔打开或关闭,例如 100 毫秒左右。如果它已关闭,则您可以重新加载父窗口。

回答by Alex Altotsky

The issue with window.opener in IE is when you using localhost site and the internet site like paypal. Simply change location of your local host from Local Intranet to the Internet zone and the opener will not be null.

IE 中 window.opener 的问题在于您使用 localhost 站点和 paypal 等 Internet 站点时。只需将本地主机的位置从本地 Intranet 更改为 Internet 区域,开启器就不会为空。