window.opener is null after redirect
Asked Answered
G

3

18

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?

Gulp answered 19/8, 2011 at 10:51 Comment(5)
What URL are you trying to access window.opener from - is it on the same domain as the opener? I'm not sure but I think the opener property should persist across redirectsDistribute
Hey Pekka, well yes the final url in the popup window has the same domain as the opener. But: When the window opens it goes directly to Paypal (https by the way). Maybe I could have another page from my domain inbetween there?Gulp
Man yes that works great! I just put another redirecting page in between. Now the popup goes first: To a page on my domain, second: To PayPal and Third: Back to my domain. This way it doesnt loose the parent information. Great MAN Thanks!Gulp
does this works in IE? i do the same and the first and third step i am on the same domain but different page, it doesn't work in IE, but works in chrome and firefox.Varietal
When using <a target="_blank"> instead of window.open(), I also needed to include rel="opener".Haworth
R
21

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.

Rhesus answered 19/8, 2011 at 10:58 Comment(4)
It is removed when navigating to a different host, but shouldn't it be available (as per the Same Origin Policy) when you navigate back to the same host? Or is it lost forever?Distribute
The browser sets it to null, it doesn't bother restoring it afterwards. For security-relevant things the simplest approach is usually the best one, here you would risk hitting race conditions otherwise.Rhesus
How do they do it? ximon.nl/… (you don't have to pay, but I tell you they close the window and refresh the url of the parent) ;-)Gulp
Now 12 years later. in 2023, have the same issue. I have 2 servers for load balancing, the postMessage works fine if my request goes to server 1 , which is a Django application running on LSWS, For server 2 I have an Apache2 server running a Django application. This works fine on Server 1 with LSWS, for Server 2 on APache2 it says, window.opener is undefinedRamage
C
5

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.

Canticle answered 19/8, 2011 at 11:10 Comment(2)
Good approach, but the parent cant check the child anymore after it looses the "child" information. That's the problem...Gulp
The parent looses the control over child only if the child window is closed, otherwise the parent will be having the control over it. So this method can be established. try it u'll find wat u needCanticle
D
4

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.

Darladarlan answered 7/6, 2015 at 20:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.