Pausing a setInterval function's execution when the page isn't in view
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?