Detect whether a window is visible [duplicate]

南笙酒味 提交于 2019-12-01 23:29:31

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!