I've been hanging around in the jQuery IRC-Channel today, when somebody came in and asked a simple question:
<simulation> how can i know if the page is on visible tab or passive tab ?
At first I thought this'd be impossible. Neither I there an API that I know of, nor should it be possible because of privacy. (Note: There are Fx internal APIs like tabs.focused
)
Thankfully recently Browser vendors added the requestAnimationFrame function. We can use that to hack something together.
load the reqAF-shim: https://gist.github.com/997619 and save it to any variable, eg reqAF.
hm, the problem I have with that is that the
requestAnimationFrame
is not optional. I need it in order for the hack to work. Plus, no browser implements it with that name yet.function(r){return function(c){setTimeout(function(){c&&c(c=!1)},50);r(function(){c&&c(!(c=0))})}}( reqAF )
^this includes
function(){}
four times. any idea to reduce it?