Document:FullScreenElement 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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
# ref-for-dom-document-fullscreenelement①

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
fullscreenElement

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Uses a non-standard name.
Requires a vendor prefix or different name for use.
Has more compatibility info.

参见