Document:FullScreenElement 属性

只读属性 Document.fullscreenElement 返回当前页面中以全屏模式呈现的 Element,如果当前页面未使用全屏模式,则返回 null

尽管这个属性是只读的,但如果修改它,即使在严格模式下也不会抛出错误;它的 setter 方法是空操作将被忽略。

返回当前处于全屏模式的 Element 对象;如果当前页面未使用全屏模式,则返回 null

示例

这个示例展示了一个名为 isVideoInFullscreen() 的函数,该函数查看 fullscreenElement 返回的值;如果文档处于全屏模式(fullscreenElement 不为 null)并且全屏元素的 nodeNameVIDEO,表示为 <video> 元素,则函数返回 true,表示视频处于全屏模式。

js
function isVideoInFullscreen() {
  if (document.fullscreenElement?.nodeName === "VIDEO") {
    return true;
  }
  return false;
}

规范

Specification
Fullscreen API Standard
# ref-for-dom-document-fullscreenelement①

浏览器兼容性

BCD tables only load in the browser

参见