Here's Piotrek De's answer on another question:
There is a neat library available on GitHub:
https://github.com/serkanyersen/ifvisible.js
Example:
// If page is visible right now
if( ifvisible.now() ){
// Display pop-up
openPopUp();
}
I've tested version 1.0.1 on all browsers I have and can confirm that it works with:
- IE9, IE10
- FF 26.0
- Chrome 34.0
and probably all newer versions.
Doesn't fully work with:
- IE8 - always indicate that tab/window is currently active (.now() always returns true for me)