特殊說明:
通過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