javascriptwindow.openchildwindow

Can't reopen child window in the same block even with a setTimeout


Here's a distillation of the problem:

If I open a console and enter the following code as a single block:

var existingWin = window.open('', 'footerContent'); 
existingWin.close();
var existingWin = window.open('', 'footerContent')

the first window.open and the window.close calls work, but the second window.open call doesn't work. Even if I delay it to give the window time to close first:

var existingWin = window.open('', 'footerContent'); 
existingWin.close();
setTimeout(function() {var existingWin = window.open('', 'footerContent')}, 3000) 

it doesn't work. But if I execute the first two lines alone:

var existingWin = window.open('', 'footerContent'); 
existingWin.close();

and then separately enter:

var existingWin = window.open('', 'footerContent'); 

it now opens the window. This suggests that the problem is running them in the same block of code.

This is causing me problems in a unit test I'm building. Can anyone help me understand why this happens and if there's a way to work around it? Thanks in advance.


Solution

  • Turns out it was a default popup blocker setting in my Chrome browser. When I changed the setting, it worked as it should. Thanks to takrishna for pointing me in the right direction. But this does mean I'll probably use a different strategy and stay away from child windows.