javascript detect user is viewing the page
<p>Currently my website keep auto reload a javascript function for every 10 seconds by <code>setInterval( "checklatestmsgidLive();", 10000 );</code> I think the function will still keep reloading the function even when the user is viewing other website on other tab. How to make it reload the function only when the user is viewing my website? Can javascript detect if the user is viewing my website?</p>

<p>I saw facebook.com wall also update new posts only when I am viewing the page, when I am on other tab, it won't update the new posts. How to do that?</p>
