1

Hello fellow developers,

I am facing an issue with accessing a pop-up window by its window name after navigating out of the page.

Here are the steps to reproduce the issue:

  • Access a html page on your browser.
  • From there, open a new named popup window:

window.open("/", "testPopup", "width=320,height=240,resizable=yes,scrollbars=yes")

  • Move out from the page to the completely different domain. For example, go to google.com.
  • Hit the back button to the previous page and attempt to access the popup with the following JavaScript code: window.open("", "testPopup")

The browser will open a new blank page instead of returning the Window object of the existing popup.

I have noticed that this technique is still usable up to Chrome 83, but we cannot use it on Chrome 84 onward. (see Access a window by window name)

My question to the community is whether there is any way to access the already opened pop-up window after navigating out from the page. If there is no solution, I would appreciate any suggestions for an alternative workaround.

Thank you in advance for your help.

Donovan P
  • 591
  • 5
  • 9

1 Answers1

-1

You can't go back to the previous window if you didn't preserve a reference to it. But, you may run JavaScript code in that window if it's still open and the page that loaded there is from the same domain as your page:

let params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,
width=0,height=0,left=-1000,top=-1000`;

open('/', 'test', params);

or call a Javascript function from within the context to see if it would fetch the currently active page instead of opening a new window. Just invoke a new window to do some checking and reopen to allow popup to be loaded.

or you can checkout this solutions here: popup-windows I hope this would help you.

Prince
  • 47
  • 7
  • I'm not sure what did you mean by preserve a reference. Like I explained, we can't with the current browser. Re running `open('/', 'test', params)` would just open another popup, which doesn't answer my question. – Donovan P Mar 09 '23 at 04:43