1

I'm using a loop with window.open inside it, and I'm looking for a way to wait for the previous window to be closed before launching the next one.

for(...){
          window.open('index.html', '_blank', 'nodeIntegration=yes');
bob dylan
  • 989
  • 2
  • 10
  • 26
  • Possible duplicate of [Communication between tabs or windows](https://stackoverflow.com/questions/28230845/communication-between-tabs-or-windows) – Baruch Feb 24 '19 at 16:00

1 Answers1

1

Simple for loop will not work. This can be achieved by setInterval. Please refer the code below.

var MyWin = null;//window obejct will assign in future
var i = 0;//Strating index of loop
var len = 5;//length of loop
var myInterval = setInterval(function () {
    if ((!MyWin || MyWin.closed) && i < len) {
        MyWin = window.open("http://www.google.com/");
        i++;
    }
    else if (i >= len) {
        clearInterval(myInterval);//dont forget to clear interval
    }
}, 100);
D Mishra
  • 1,518
  • 1
  • 13
  • 17