Document:fullscreenerror 事件

Limited availability

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

fullscreenerror 事件在浏览器不能切换全屏模式时触发。

fullscreenchange 事件一样,会触发两个 fullscreenerror 事件;第一个事件会发送给未能更改模式的 Element,第二个事件会发送给拥有该元素的 Document

有关切换到全屏模式可能失败的原因,请参阅全屏 API 指南

该事件不可取消。

语法

在类似于 addEventListener() 的方法中使用事件名称,或设置事件处理器属性。

js
addEventListener("fullscreenerror", (event) => {});

onfullscreenerror = (event) => {};

事件类型

通用的 Event

示例

js
const requestor = document.querySelector("div");

function handleError(event) {
  console.error("切换至全屏模式时发生错误");
  console.log(event);
}

document.addEventListener("fullscreenerror", handleError);
// 或
document.onfullscreenerror = handleError;

requestor.requestFullscreen();

规范

Specification
Fullscreen API
# handler-document-onfullscreenerror

浏览器兼容性

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
fullscreenerror event

Legend

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

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

参见