Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep refreshing the page periodically while the user is away from the page? and not to refresh if on the page
    text
    copied!<p>Is it possible to refresh a webpage, say, every minute when the user is NOT on the page? For example, if I am visiting a PageX and stay on the page it doesn't refresh but as soon as I navigate away from the page (that is, switch to another tab/window or a program, then the PageX refreshes every x minutes or seconds? How do I go about this? Thx.</p> <p><strong>Update:</strong></p> <p>"on the page" means the page is the current window i.e. it has focus. So if the PageX has a link to a pop window, say 100 x 100, clicking that opens the popup, while the page is still kind of visible behind that tiny popup window, it doesn't have a focus, hence needs refresh as stated above.</p> <p>Any thing not clear please ask.</p> <p><strong>Update 2</strong></p> <p>As suggested by Mattk below .. Following seems to be working in Firefox (haven't checked in the latest), and Chrome. In the IE 8, if I switch to another tab or a program, it doesnt' refresh the page, but if I am on the page and click in the address bar, it starts refreshing the page. Any ideas how to get it working in IE?</p> <pre><code>var pageFocused = false; function onPageFocus(){ pageFocused = true; //document.body.className = 'focused'; } function onPageBlur() { pageFocused = false; //document.body.className = 'blurred'; }; function checkActivity() { if(pageFocused == false){ location.reload(true); } } setInterval("checkActivity()", 1 * 1000); if (!+"\v1") { // check for Internet Explorer document.onfocusin = onPageFocus; document.onfocusout = onPageBlur; } else if (/*@cc_on!@*/false) { document.onfocusin = onPageFocus; document.onfocusout = onPageBlur; } else { window.onfocus = onPageFocus; window.onblur = onPageBlur; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload