18910140161

[HTML5] document.hidden

顺晟科技

2022-09-15 22:28:13

195

特殊说明:

通过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

我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航