How can it be detected if a page is on background or foreground with jquery/javascript?
<p>The title explains itself. How can I detect if a web page has gone to background?</p>

<p>I'm implementing a chat application and I'll use this information to decide showing new message notifications. I suppose that GMail uses something like that. If the page is on background, it shows desktop notifications (on chrome), if not it doesn't show them.</p>
