Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda