Skip to content Skip to sidebar Skip to footer

Detect Whether A Window Is Visible

Possible Duplicate: Javascript: Is there any way to detect that window is currently active? (i.e. is beening shown on active tab/window) I have a web-based dashboard which displ

Solution 1:

You can use the Page Visibility API in browsers that support it. Otherwise as you said you will need to use a hack with onfocus/onblur.

visibility.js is a library that abstracts this across all browsers. It will use the onblur/onfocus hack if the browser does not support the Page Visibility API.

function isPageHidden(){
     return document.hidden || document.msHidden || document.webkitHidden || document.mozHidden;
 }

Source: http://www.nczonline.net/blog/2011/08/09/introduction-to-the-page-visibility-api/

Read: https://developer.mozilla.org/en-US/docs/DOM/Using_the_Page_Visibility_API


Post a Comment for "Detect Whether A Window Is Visible"