1

There are many similar questions like this and this about accessing blocked pop-up windows, but none fit these circumstances.

User Flow:

  • User clicks button.

  • Button click triggers async server call. When server call returns (> 1-2 seconds), JavaScript code opens new window (with same domain).

  • Most browsers block this new window as documented by other questions.

  • Our current workaround is to poll every 3 seconds to see if a window is open. The problem with this approach is the code opens multiple windows, even though we only want one.

  • Using window.opener from the newly opened window seems unreliable as some answers suggest window.opener is not consistently accessible in FireFox and Safari.

Hence this question: is there a window event we can subscribe to that gets invoked when a blocked pop-up finally gets open?

Ultimately, the goal is to invoke code in the new window as soon as it opens and is ready.

var DownloadWindow = window.open("newURL", "uniqueWindowID");

*** 1-2 seconds later ***

startTest();

function startTest() {
   // <DownloadWindow> doesn't exist yet? Set timeout and check back later.
   var delayDur = 3000;
   if (!DownloadWindow) {
      DownloadWindow = openDownloadWindow();
      setTimeout(startTest, delayDur);
      return;
   }

   // Do stuff.
}
Crashalot
  • 33,605
  • 61
  • 269
  • 439

0 Answers0