Document:fullscreen 属性

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

过时的 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,表示全屏模式正处于生效状态。

规范

Specification
Fullscreen API
# dom-document-fullscreen

浏览器兼容性

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
fullscreen
Deprecated

Legend

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

Full support
Full support
Partial support
Partial support
No support
No support
Deprecated. Not for use in new websites.
Uses a non-standard name.
Has more compatibility info.

参见