Skip to content

Commit

Permalink
[zh-cn] update fullscreenerror event of document
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonren0403 authored Nov 30, 2023
1 parent 46513d2 commit bf424b2
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions files/zh-cn/web/api/document/fullscreenerror_event/index.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
---
title: Document.onfullscreenerror
title: Document:fullscreenerror 事件
slug: Web/API/Document/fullscreenerror_event
l10n:
sourceCommit: 41a8b9c9832359d445d136b6d7a8a28737badc6b
---

{{ApiRef("Fullscreen API")}}
{{ApiRef}}

Document.onfullscreenerror 属性是一个事件处理器用于处理 [`fullscreenchange`](/zh-CN/docs/Web/API/Document/fullscreenchange_event) 事件,在当前文档不能进入全屏模式,即使它被请求时触发。
当浏览器不能切换至全屏模式时,会触发 `fullscreenerror` 事件。

[`fullscreenchange` 事件](/zh-CN/docs/Web/API/Document/fullscreenchange_event)一样,会触发两个 `fullscreenerror` 事件;第一个事件会发送给未能更改模式的 {{domxref("Element")}},第二个事件会发送给拥有该元素的 {{domxref("Document")}}。

有关切换到全屏模式可能失败的原因,请参阅[全屏 API 指南](/zh-CN/docs/Web/API/Fullscreen_API/Guide)

该事件不可取消。

## 语法

```plain
targetDocument.onfullscreenerror = fullscreenErrorHandler;
在类似于 {{domxref("EventTarget.addEventListener", "addEventListener()")}} 的方法中使用事件名称,或设置事件处理器属性。

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

onfullscreenerror = (event) => {};
```

## 事件类型

通用的 {{domxref("Event")}}。

## 示例

```js
document.onfullscreenerror = function (event) {
console.log("FULL SCREEN DENIED");
};
const requestor = document.querySelector("div");

function handleError(event) {
console.error("an error occurred changing into fullscreen");
console.log(event);
}

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

// requestFullscreen() 将会失败,因为它在事件处理器之外
document.documentElement.requestFullscreen();
requestor.requestFullscreen();
```

## 规范
Expand All @@ -32,7 +54,9 @@ document.documentElement.requestFullscreen();

{{Compat}}

## 相关文章
## 参见

- [`fullscreenerror`](/zh-CN/docs/Web/API/Document/fullscreenerror_event)
- {{domxref("Document.onfullscreenchange")}}
- {{domxref("Document/fullscreenchange_event", "fullscreenchange")}}
- {{domxref("Element")}}:{{domxref("Element/fullscreenerror_event", "fullscreenerror")}} 事件
- [全屏 API](/zh-CN/docs/Web/API/Fullscreen_API)
- [全屏 API 使用指南](/en-US/docs/Web/API/Fullscreen_API/Guide)

0 comments on commit bf424b2

Please sign in to comment.