the parent window can only be accessed using the parent variable.
The following modification to opener1 function should make this possible
function opener1(){
try{
if(parent.window.opener != null && !parent.window.opener.closed)
{
parent.window.opener.test1();
}
}catch(e){ alert(e.description);}
}
Answer from anurupr on Stack Overflowthe parent window can only be accessed using the parent variable.
The following modification to opener1 function should make this possible
function opener1(){
try{
if(parent.window.opener != null && !parent.window.opener.closed)
{
parent.window.opener.test1();
}
}catch(e){ alert(e.description);}
}
Code seems to be fine for me. If you catch an exception you can log it to console to get information of what is wrong. Make sure domains of test1.html and test2.html match, otherwise you will get security exception.
Issue with Chrome 108 and window opener.
window.opener returns null in chrome version >88
window.opener is null on android chrome (but not in incognito)
window.opener is null in firefox - javascript
One of our websites references the opener window when a link is clicked and a new tab is opened. Prior to Google Chrome 108 this worked fine, but now opener returns null.
This works in other browsers.
Any idea how to correct this?
You open a window from another domain/subdomain. In this case you don't have access to parent window that opened the target window because security permissions don't allow that.
For example, if you open a page of site2.com from a page of site1.com the target window has it's opener null.
If you open a page of site2.site.com from a page of site1.site.com — it's also no access because these are two different sites.
But if you a page of site.com page from page of site.com or page of subdomain.site.com from page of site.com — you have the access because security permissions allow that.
Note: maybe 'prcsTypeSelectionPopup?event=prcsTypeSelection' is incorrect. Change it to root correct path without domain, an example:
/prcsTypeSelectionPopup?event=prcsTypeSelection
it works only for "parent.window.opener" and not for "window.opener"
Thanks Sergzach for your time
From what I could find the window.open will return null when it fails to open. Something may be keeping the browser from opening additional windows a couple of times; maybe it is a popup blocker.
The actual loading of the url and creation of the window are done asynchronously.
https://developer.mozilla.org/en-US/docs/Web/API/Window.open
Popup blocking
In the past, evil sites abused popups a lot. A bad page could open tons of popup windows with ads. So now most browsers try to block popups and protect the user.
Most browsers block popups if they are called outside of user-triggered event handlers like onclick.
For example:
// popup blocked window.open('https://javascript.info'); // popup allowed button.onclick = () => { window.open('https://javascript.info'); };
Source: https://javascript.info/popup-windows
I'm working with Google OAuth in my React application, and I'm implementing it through a popup. I'm using Passport with my custom backend. The initial URL that I supply to the popup window is the backend entry point that initializes the OAuth process. Google then sends a response to my callback on my backend.
After that, I need to communicate the JWT access token back that I generate on the backend to my frontend. I'm doing this by redirecting respondign with a redirect to a frontend route, with the access token as a query parameter in the redirect URL. The problem I'm facing, however, is that the window.opener in the popup becomes null after the Google OAuth process. This prevents me from sending the access token back to the parent window using window.opener.postMessage.
I have verified that the window.opener is not null when I pass in the same route my backend redirects my frontend to, as the initial url to the popup. The issue occurs when I pass in my backend endpoint for initializing google OAUTH (so it redirects to Googles sign in).
Unfortunately, I can't use cookies or localStorage due to my application's restrictions.
Has anyone faced a similar issue? Any advice or guidance would be greatly appreciated. Thanks!