最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - After refresh setTimeout will work or Not? - Stack Overflow

programmeradmin0浏览0评论

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);

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);
Share Improve this question asked May 18, 2016 at 11:51 Raj_KingRaj_King 5563 silver badges13 bronze badges 2
  • Yes it will work, after 3 mins of page reload – Satpal Commented May 18, 2016 at 11:53
  • @Satpal Thanks for ur reply – Raj_King Commented May 18, 2016 at 11:59
Add a ment  | 

2 Answers 2

Reset to default 5

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.

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.
发布评论

评论列表(0)

  1. 暂无评论