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

196
Views
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 answers
Answer question

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