Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delay a javascript function

Tags:

javascript

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();
};
like image 250
Mohamed Ashraf Fahim Avatar asked Nov 20 '25 19:11

Mohamed Ashraf Fahim


1 Answers

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

like image 113
Lundstromski Avatar answered Nov 22 '25 10:11

Lundstromski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!