Reputation: 1109
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');
Upvotes: 1
Views: 340
Reputation: 1578
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);
Upvotes: 1