Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Client-side Scripting _ Stop JavaScript when tab in background

Posted by: denmarks Dec 4 2021, 11:54 AM

It there a way to stop JavaScript when tab is in the background? I have a local webpage. It is not on a server. I keep it in one of my tabs. Is there anyway to create a looping JavaScript that will pause when the page is in the background and resume when the page is active? For example, if I had a counter counting down seconds, can the script be stopped when not viewing the page to cut down the overhead?

Posted by: pandy Dec 4 2021, 12:20 PM

There's window.document.hasFocus() .

Posted by: Ashly Rivera Jan 4 2022, 04:15 AM

Did you have a fix on this issue? Facing same issue but no response from anyone and couldnt find this topic troubleshooting in google.

Posted by: denmarks Jan 4 2022, 09:41 AM

QUOTE(Ashly Rivera @ Jan 4 2022, 01:15 AM) *

Did you have a fix on this issue? Facing same issue but no response from anyone and couldnt find this topic troubleshooting in google.

The above post may work but I did not want to go through the trouble making the change. The code was only used for a page that is executed on my computer and not a website.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)