Search code examples
javascriptjquerytabsrefreshmilliseconds

How to reload a tab every 5 seconds if it is not active


Hi guys I've read a lots of similar questions but I can't find a specific solution for that.

I try this...but works only for the first reload than after the page is refresh in the background it'll not realod again alone after 5 seconds.

var isActive;

window.onfocus = function () { 
  isActive = true; 
}; 

window.onblur = function () { 
  isActive = false; 
}; 
setInterval(function () { 
  if (isActive == false) {location.reload();}
}, 5000);

Thank u.


Solution

  • i solve with this.... jsfiddle.net/wve3H

    Thank u to everyone