此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Document:fullscreen 属性

Deprecated

Avoid using this feature in new projects. This feature may be a candidate for removal from web standards or browsers.

过时的 Document 接口的 fullscreen 只读属性表明页面当前是否以全屏模式显示内容。

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

备注:由于该属性已被弃用,你可以通过检查 Document.fullscreenElement 是否不为 null 来确定页面是否处于全屏模式。

返回一个布尔值,如果页面当前在全屏模式下显示元素,则为 true;否则为 false

示例

这个简单的函数使用过时的 fullscreen 属性报告当前是否激活了全屏模式。

js
function isDocumentInFullScreenMode() {
  return document.fullscreen;
}

另一方面,下面的示例使用当前的 fullscreenElement 属性来确定同样的事情:

js
function isDocumentInFullScreenMode() {
  return document.fullscreenElement !== null;
}

如果 fullscreenElement 不为 null,则返回 true,表示全屏模式正处于生效状态。

规范

规范
Fullscreen API
# dom-document-fullscreen

浏览器兼容性

参见