window.opener is null after redirect

天大地大妈咪最大 提交于 2019-11-26 09:48:02

问题


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.

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

However the console shows

window.opener.location is null

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?


回答1:


window.opener is 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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/7120534/window-opener-is-null-after-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!