Is it possible for a window to retain a window.opener reference without having been opened by window.open()?

550 views Asked by At

I'm wondering if it is possible in the newer versions of JavaScript (I'm using React ES6, if that factors in at all) for a script in a window to have a window.opener where window.opener !== null, without having first been opened by the same script using the open() command? That's a confusing question so let me try to clarify.

I am currently experiencing a console error in my JS application (run in Chrome) that reads: Scripts may not close windows that were not opened by script. I've seen many questions on SO detailing workarounds for using window.close() on a window that wasn't opened by the current script, but that's not quite my question. My code reads:

if (window.opener) {
  window.close();
} else {
  // do something else
}

window.close() is, as far as I know, the only function which can generate this browser error Scripts may not close windows that were not opened by script. But I also would have thought that if there were a non-null reference to window.opener, the same script I'm running must have been the opener of the current window. So, how is window.close() erroring out, saying that this script didn't open the window, but there's a window.opener reference which is non-null?

0

There are 0 answers