[HTML5] document.hidden

特殊说明:

通过document.hidden属性,可判断页面是否可见。 如果不可见,则document.hidden为true. 如果可见, 则为false。

但是, 如果该页面只是被其它窗口挡住, 而非最小化该页面。 则document.hidden仍然是false. 而不是不可见。

Example:

//startSimulation and pauseSimulation defined elsewhere
function handleVisibilityChange() {
  if (document.hidden) {
    pauseSimulation();
  } else  {
    startSimulation();
  }
}

document.addEventListener("visibilitychange", handleVisibilityChange, false);

see:

https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API

原文地址:https://www.cnblogs.com/mytianying/p/5668507.html