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

140
Views
How to ensure that all onclick events on clicked domnode got executed before the page navigates to another page

We are working on an Open Source Chrome extension: Digital Assistant Client

Product Demo:

Part 1: https://www.youtube.com/watch?v=Iz2WgKY0fhc

Part 2: https://www.youtube.com/watch?v=i0_MNfBnYfM

We are having trouble in getting our onclick event handler executed when the page is navigated to another page.

I want to invoke all the onclick event handlers attached to a domnode that the user has clicked before the page gets navigated to another page so that our functionality gets executed. The solution should work for any framework that cancels the bubbling of the onclick event handlers.

There are some questions already raised by some people as given below

  1. How to ensure that a function is executed completely, before navigating to another page?
  2. How to execute onclick before navigating to a different page?

Thanks in advance

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

0

You can probably monkey-patch addEventListener on the DOM Node, capture the event handlers that get registered later, and maintain a list of those.

const originalEventListener = DOMNode.addEventListener;
DOMNode.addEventListener = (type, callback) => {
  const clicksHandler = [];
  if(type === 'click'){
    clicksHandler.push(callback);
    originalEventListener.call(DOMNode, type, callback);
  }
}

You can probably use beforeunload event to make sure all the clicksHandler are called once again before user navigates away.

window.onbeforeunload = (e) => {
  clickHandler.forEach((handler) => handler.call(...))
}
about 4 years ago · Juan Pablo Isaza Report

0

you just have to call the event on that element.

const button1 = document.getElementBy....

button1.click()
about 4 years ago · Juan Pablo Isaza Report

0

add alert before navigation inside click method, so alert will notify you.

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!