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

83
Views
How to make JavaScript Snippets work after page reloads, in Chrome?

Environment: Chrome, a simple Web Portal

I'm trying to do a simple browser automation.

In a HTML table, 1. Clicks the first link, 2. Change the dropdown value and 3. click Submit.

The code after button click is not executed, as the page loads after the button click.

var tbl = document.getElementById("incident_table")
tbl.rows[2].cells[2].getElementsbyClassName("linked")[0].click()
// below code is not executing, as the above click loads the page
document.getElementById("incident.state").selectedIndex = 1
document.getElementById("sysverb_update").click()

I can able to run the last 2 lines of code separately in console, it works.

But when executing as a snippet it didnt

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

this post is very similar to your question: preventDefault() on an <a> tag

what you want to do is prevent the default action of the javascript click event.

What you may also do is:

tbl.rows[2].cells[2].getElementsbyClassName("linked")[0].addEventListener('click', ()=>{
    preventDefault();
    //write here what should happen instead
    });

What this will do is prevent the default action "reload site" from happening

Edit: What i mean in the comment is the following:

if(localStorage.getItem("firstPartComplete") === null){
   //do first part
   //set completion status in localStorage
   localStorage.setItem("firstPartComplete", true);
}else{
   // do second part
   localStorage.removeItem("firstPartComplete");
}
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!