i have a javascript to parse twitter feeds and show them in a block in my page every 30 seconds, the code is something like this:
var auto_refresh = setInterval( function () { //get twitter feeds }); }, 30000);
now in case the user minimized his browser or switched to another tab (page is not active) i want to disable this auto_referesh clearInterval(auto_refresh);
Thanks for your help
Here is the answer:
Is there a way to detect if a browser window is not currently active?
You may want to check out
Also note that Chrome apparently has some optimizations that slow down the firing of the timer when the tab is not in focus: How can I make setInterval also work when a tab is inactive in Chrome?
This answere is pretty clean: https://stackoverflow.com/a/18677784/9027171
An excerpt from the answer of infinito84
if(!document.hasFocus()){
// The tab is not active
}
else{
// The tab is active
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.