We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE


 Document.visibilityState (只读属性), 返回document的可见性, 即当前可见元素的上下文环境. 由此可以知道当前文档(即为页面)是在背后, 或是不可见的隐藏的标签页,或者(正在)预渲染.可用的值如下:

  • 'visible' : 此时页面内容至少是部分可见. 即此页面在前景标签页中,并且窗口没有最小化.
  • 'hidden' : 此时页面对用户不可见. 即文档处于背景标签页或者窗口处于最小化状态,或者操作系统正处于 '锁屏状态' .
  • 'prerender' : 页面此时正在渲染中, 因此是不可见的 (considered hidden for purposes of document.hidden). 文档只能从此状态开始,永远不能从其他值变为此状态.注意: 浏览器支持是可选的.
  • 'unloaded' : 页面从内存中卸载清除. 注意: 浏览器支持是可选的.

当此属性的值改变时, 会递交 visibilitychange 事件给Document.

典型用法是防止当页面正在渲染时加载资源, 或者当页面在背景中或窗口最小化时禁止某些活动.


var string = document.visibilityState


document.addEventListener("visibilitychange", function() {
  console.log( document.visibilityState );
  // Modify behavior...


Specification Status Comment
Page Visibility (Second Edition)
Recommendation Initial definition.


We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 13 webkit
18 (18) [2] 10 12.10[1] 7
prerender (Yes) 49 (49) ? ? ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 4.4 webkit 18.0 (18) [2] ? 12.10[1] 7
prerender (Yes) 49.0 (49) ? ??

[1] Doesn't fire the visibilitychange event when the browser window is minimized, nor set hidden to true.

[2] From Firefox 10 to Firefox 51 included, this property could be used prefixed with -moz-.


 此页面的贡献者: nDos, vanishcode, printfalling
 最后编辑者: nDos,