Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zh-cn] update fullscreenerror event of document #17202

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("切换至全屏模式时发生错误");
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)
yin1999 marked this conversation as resolved.
Show resolved Hide resolved
Loading