Click here to Skip to main content
16,018,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to make a script that does a sequence of clicking on buttons.
The tricky part is that each time you click a button it will direct you to another page.

Thanks in advance!

What I have tried:

...
document.getElementById('id1').click();
//works fine until here

//This part is not running. It makes sense because it should only run after being in the next loaded page. I thought the timeout would work but it does not.
setTimeout(() => {document.getElementById(id2').click()}, 5000);
end();
Posted
Updated 10-Sep-22 11:16am

1 solution

To stop the form from reloading when you click button you need to stop the event bubbling up through to the form by doinf something like this;
<body onclick="alert(`the bubbling doesn't reach here`)">
  <button onclick="event.stopPropagation()">Click me</button>
</body>


See this article; /bubbling-and-capturing[^]
 
Share this answer
 
Comments
Taredan 10-Sep-22 18:06pm    
The second button is in the page loaded from the clicking of the first button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900