Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

79
Views
Looping through array of file urls opens only first URL Javascript

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.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report

0

**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>

about 4 years ago · Juan Pablo Isaza Report

0

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); 
 }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!