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

221
Views
using vanilla js how do i make the url update

how do i make the window.location.url update every 30 seconds to the next id found in the array. Right now i have it alerting hello every few seconds but want the url to change instead

    const myIds=['1_aq4jiqb','1_4u0ocu4u'];

for (let i = 0; i < myIds.length; i++) {
window.location.href = 'https://yahoo.com' + myIds[i]+ '/embed/iframe?';

}
setInterval(function(){ alert("Hello"); }, 3000);
<html>


</html>

update to the next Id after 30 seconds?

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

0

It's not possible unless you control each of those sites that you're redirecting to.

When you do window.location.href =, an entirely new document is loaded, with (and with only) the JavaScript(s) that new document links to. Anything that happens in your code after a single window.location.href = runs will be effectively ignored, because your old JavaScript does not carry over to the newly-loaded page.

Unless you control each of the sites you're redirecting to, the only way to accomplish this (on your browser only) would be to inject JavaScript code of your own into every site with a userscript.

about 4 years ago · Juan Pablo Isaza Report

0

If I understand what your're asking, just put the code inside a function, and call that at the setInterval.

const myIds=['1_aq4jiqb','1_4u0ocu4u'];

function switchId() {
  for (let i = 0; i < myIds.length; i++) {
    window.location.href = 'https://yahoo.com' + myIds[i]+ '/embed/iframe?';
  }
}

setInterval(function(){ switchId() }, 3000);
<html>


</html>

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!