Document:fullscreenEnabled 属性

Document 接口上的只读属性 fullscreenEnabled 表明全屏模式是否可用。

全屏模式仅适用于不包含任何窗口化插件的页面,或者页面中的所有 <iframe> 元素都设置了 allowfullscreen 属性。

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

一个布尔值,如果调用 Element.requestFullscreen() 能进入全屏模式,则为 true。如果全屏模式不可用,则该值为 false

示例

在下面的示例中,在 <video> 元素尝试请求全屏模式之前,检查 fullscreenEnabled 的值,以避免在不可用时调用 Element.requestFullscreen() 方法。

js
function requestFullscreen() {
  if (document.fullscreenEnabled) {
    videoElement.requestFullscreen();
  } else {
    console.log("你的浏览器现在无法使用全屏模式");
  }
}

规范

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

浏览器兼容性

BCD tables only load in the browser

参见