--- title: Document.onvisibilitychange slug: Web/API/Document/onvisibilitychange translation_of: Web/API/Document/onvisibilitychange ---
{{ApiRef('DOM')}}

Document.onvisibilitychange 是一个事件处理方法,它将在该对象的 visibilitychange事件被触发时调用。

Syntax

obj.onvisibilitychange = function;

例子

document.onvisibilitychange = function() {
  console.log("Visibility of page has changed!");
};

标准

Specification Status Comment
{{SpecName('Page Visibility API','#onvisiblitychange-event-handler','onvisibilitychange')}} {{Spec2('Page Visibility API')}} Initial definition.

浏览器兼容性

{{Compat("api.Document.onvisibilitychange")}}

另见