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

195
Visualizações
How to open 3 different links, that is a different link each time on cycle on 3 clicks in javascript

I need a logic to loop 3 URLs on the cycle of 3 clicks . like after every 3rd click I want the link to be changed . .

   {
        if(Get_Cookie("pagecount") % 3 === 0)
        self.location.href="https://www.google.com";
        else
        self.location.href="https://www.wikipedia.com"";
   }

This is the logic I used to loop two different links on third click. but I need three different links to cycle. Here ,Get_Cookie("pagecount") returns the number of times I'm clicking the URL on the next three clicks I want

self.location.href="https://www.facebook.com"";
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can put the links in an array, and cycle through that. This has the benefit of being able to add as many links to the array as you want.

const links = ["https://www.google.com","https://www.facebook.com","https://www.stackoverflow.com"];
const timesToRepeat = 3;

let clickCount = 0;

document.getElementById("btn").onclick = (e) => {
  console.log(links[Math.floor(clickCount / timesToRepeat) % links.length]);
  clickCount += 1;
};
<button id="btn">Click</button>

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