Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After refresh setTimeout will work or Not?

I have script like below. if i refresh a page before (3 Minutes)setTimeout, get_details function call will work or not?

setTimeout(function() {
    get_details(user);
}, 18000);
like image 453
Raj_King Avatar asked Sep 13 '26 03:09

Raj_King


2 Answers

If you refresh while the timer is running it will start all over again when the page reloads.

So to answer your question, yes the get_details() function will be called after the refresh but only after the full 3 minutes has elapsed since the refresh occurred.

like image 97
Rory McCrossan Avatar answered Sep 15 '26 16:09

Rory McCrossan


It depends when you invoke the setTimeout:

  • setTimeout invoked on dom ready - Yes, get_details() will run after 180 sec
  • setTimout invoked on event (e.g. button click) - Button was clicked --> setTimeout has been invoked --> page was refreshed, the queue of the event loop was cleared and get_details will not be invoked.
like image 26
chenop Avatar answered Sep 15 '26 15:09

chenop



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!