I've this short script to open URL's:
var x = document.querySelectorAll("a.Mylinks");
var myarray = [];
for (var i = 0; i < x.length; i++) {
var link = x[i].href;
myarray.push(link);
}
for (var i = 0; i < myarray.length; i++) {
window.open(myarray[i], "_blank");
}
Array responds back with correct URLs, first URL opens and that is it, loop stops. Any ideas why this is happening and how this can be fixed? Any additional links or information would be helpful.
Thanks in advance.
The problem you're facing is that browser you're using blocks an opening of too much tabs at the same time. Try disabling that blocking, usually you can find the needed button for that in the address bar.
**Note Browser can block as opening of too much tabs at the same time.**
var x = document.querySelectorAll("a.Mylinks");
var myarray = [];
for (var i = 0; i < x.length; i++) {
var link = x[i].href;
window.open(x[i].href,Math.floor(Math.random() * 80000));
}
<a class='Mylinks' href='https://google.com'></a>
<a class='Mylinks' href='https://stackoverflow.com'></a>
<a class='Mylinks' href='https://nodejs.org'></a>
Just change the target name from _blank to random series like "_blank" + i, then check it.
for (var i = 0; i < myarray.length; i++) {
window.open(link, '_blank' + i);
}