Document:fullscreenEnabled 属性

Limited availability

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

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

浏览器兼容性

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
fullscreenEnabled

Legend

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

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

参见