Window.opener is useless after redirecting in a popup (JavaScript)

I am creating an application that includes third-party authentication. To prevent the process from redirecting the actual application, I open a new window, which then authenticates and returns to the main window after success.

However, this is not as planned. When a popup is redirected to a third-party and vice versa, window.opener gets null . You can still close the popup window window.close() , but I also need to update the registered area in the main window, for example:

 window.opener.check_auth_status(); 

I really hope there is a way to fix this, for example. to bind a function to a popup in the main window? Updating the entire page would be extremely unnecessary.

One way: set the spacing in the main window to check if the popup is closed, but it seems so inconvenient.

+6
source share
1 answer

You have several options that may or may not work in recent browsers due to security updates.

1) make sure that the window is closed from the opener - not difficult and actually safer

2) give the opening name

 window.name="myMainWindow"; 

and in popup (script from the SAME domain) - usually you should not open a new window or change the content

 var handle = window.open("","myMainWindow"); handle.check_auth_status(); 

3) use the iFrame in the popup, and when you want to access the opening device, use top.opener

+9
source

Source: https://habr.com/ru/post/905489/


All Articles