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

186
Views
How to stop JS autoclick loop

I've made a script that auto-click a button on load. This button will add an item on cart and also make a pop-up. After you click the close pop-up icon, the page will be refreshed and triggering auto-click loop. Is there a way to bypass this?

my script:

var a = document.getElementById("discount");
if (discount.dataset.value === "TEST"){for ( var i = 0; i < 50; i++ ) {
  document.getElementById("clickMe").click();
}}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Check if this is working for you!

if (!localStorage.getItem('autoClick')) { // check if code already ran
  // if not then do the clicks

  var a = document.getElementById("discount");
  if (discount.dataset.value === "TEST"){for ( 
  var i = 0; i < 50; i++ ) {
    document.getElementById("clickMe").click();
  }}

  localStorage.setItem('autoClick', true); // save that you did the clicks
} else {
  // if you did the click and pop-up refreshed the page, 
  // let's remove the state so you can auto click again on next refresh
  localStorage.removeItem('autoClick'); 
}
about 4 years ago · Juan Pablo Isaza Report

0

Try use 'break' in you 'for loop'.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break

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!