I use this code and it works so that when i reload the page the button is autoclicked but i want to make a delay so that it will be clicked after 60 seconds from page reloading
window.onload = function () {
var button = document.getElementById('clickButton');
button.form.submit();
};
Andy
63.7k13 gold badges72 silver badges99 bronze badges
asked Dec 3, 2021 at 23:04
Mohamed Ashraf Fahim
337 bronze badges
2 Answers 2
window.onload = function() {
setTimeout(() => {
var button = document.getElementById('clickButton');
button.form.submit();
}, 60000);
}
Use setTimeout() https://developer.mozilla.org/en-US/docs/Web/API/setTimeout
answered Dec 3, 2021 at 23:06
Lundstromski
1,2572 gold badges9 silver badges18 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Mohamed Ashraf Fahim
I tried this and it didn't work
CherryDT
What does "it didn't work" mean? What was the behavior? Any error in the console?
To delay a page to execute some function use setTimeout takes in most cases two arguments the first is the function to be excuted after such a amount of time given by the second argument in ms
setTimeout(
function(){
var button = document.getElementById('clickButton');
button.form.submit();
}
, 60*1000);//60 * 1000 = 60000ms = 60s
answered Dec 3, 2021 at 23:08
TAHER El Mehdi
9,6647 gold badges33 silver badges52 bronze badges
4 Comments
Andy
setTimeout accepts multiple arguments.TAHER El Mehdi
yes but in most cases we use two, in his case, but we could also use Additional arguments which are passed through to the function specified by function.
Mohamed Ashraf Fahim
If i have a button on my page how to make this button disappears for a while and auto be clicked after whis while so that the user can watch ads after that the button will be autoclicked
TAHER El Mehdi
You could hide it using CSS property like
button.style.visibility='hidden'; lang-js
setTimeout.