Reputation: 538
I'm trying to execute JavaScript code that will simulate a repeated button click. Each click refreshes the webpage. Here is my code below:
for(i=0; i<1000; i++) {
console.log(i);
document.getElementById('button-id').click()
window.onload = function () { }
}
However, when I execute this, JavaScript prints out all 1000 values of i, then clicks the button only once.
Is it possible to "wait" until the page refreshes and then re-click the same button on the refreshed page?
Upvotes: 0
Views: 278
Reputation:
In JavaScript, each time you reload the page, it resets the loops that you are in. Therefore, with JS alone, what you are asking for is not possible. However, you could (I'm not sure why you would) reload the page every time it loads.
It's really simple and I would never do this, but for educational purposes, here you go:
<body onload="location.reload()">
Hope this helps!
Upvotes: 3