Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda