Does a JavaScript setTimeout function stop when page reloaded?

前端 未结 3 1082
南旧
南旧 2021-01-13 23:51

If I initiate a setTimeout function from the trigger, will the function stop when the page is reloaded?

I initiate a setTimeout function \"periodic_update()\" on th

3条回答
  •  清酒与你
    2021-01-14 00:33

    In the browser, all JavaScript code is aborted when you leave the page, and run when you open the page. So timeouts will be cleared and set again when you reload a page.

    If you want to persist a timeout, you could:

    • use a parent frame which doesn't reload
    • use localStorage (which allows you to persist data on the client's computer) to keep track of when the function was last called, and set the timeout appropriately on load

提交回复
热议问题