Pausing setInterval when page/ browser is out of focus
问题 I have a simple slideshow that I've made on a client's homepage, using setInterval to time the rotations. To prevent browsers from screwing up setInterval when the page isn't in focus (another tab is being viewed, or another programme), I'm using: function onBlur() { clearInterval(play); }; function onFocus() { mySlideRotateFunction(); }; if (/*@cc_on!@*/false) { document.onfocusin = onFocus; document.onfocusout = onBlur; } else { window.onfocus = onFocus; window.onblur = onBlur; } Where