Click here to Skip to main content
15,559,975 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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:

//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);
Updated 10-Sep-22 12:16pm

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>

See this article; /bubbling-and-capturing[^]
Share this answer
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