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

194
Views
Cómo abrir 3 enlaces diferentes, es decir, un enlace diferente cada vez en ciclo con 3 clics en javascript

Necesito una lógica para hacer un bucle de 3 URL en el ciclo de 3 clics. como después de cada tercer clic, quiero que se cambie el enlace. .

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

Esta es la lógica que usé para enlazar dos enlaces diferentes en el tercer clic. pero necesito tres enlaces diferentes para el ciclo. Aquí, Get_Cookie("pagecount") devuelve la cantidad de veces que hago clic en la URL en los próximos tres clics que quiero

 self.location.href="https://www.facebook.com"";
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede poner los enlaces en una matriz y recorrerlos. Esto tiene la ventaja de poder agregar tantos enlaces a la matriz como desee.

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