Sign in
Log inSign up

Pausing a setInterval function's execution when the page isn't in view

Emmanuel's photo
Emmanuel
·Aug 15, 2018

Is there a way to pause a function's execution when a user leaves a page?

eg if I have something like: setInterval(cleanGarbage, 3000);

Is there a way to pause it when the user switches his/her tab to a different page, so the function doesn't keep running every 3 seconds while the user isn't even viewing the page?

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2025 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct