3

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
1
  • 4
    setTimeout. Commented Dec 3, 2021 at 23:06

2 Answers 2

3
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
Sign up to request clarification or add additional context in comments.

2 Comments

I tried this and it didn't work
What does "it didn't work" mean? What was the behavior? Any error in the console?
0

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

4 Comments

setTimeout accepts multiple arguments.
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.
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
You could hide it using CSS property like button.style.visibility='hidden';

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.