From bf424b2963c74cffdd09a70f77940fca8ba787b9 Mon Sep 17 00:00:00 2001 From: Jason Ren <40999116+jasonren0403@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:22:01 +0800 Subject: [PATCH 1/3] [zh-cn] update fullscreenerror event of document --- .../document/fullscreenerror_event/index.md | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/files/zh-cn/web/api/document/fullscreenerror_event/index.md b/files/zh-cn/web/api/document/fullscreenerror_event/index.md index 0af2b39c325e63..1d2cccfe941cb6 100644 --- a/files/zh-cn/web/api/document/fullscreenerror_event/index.md +++ b/files/zh-cn/web/api/document/fullscreenerror_event/index.md @@ -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(); ``` ## 规范 @@ -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) From 436c83a841e52623ebdd084f9535c72d0373aaab Mon Sep 17 00:00:00 2001 From: Jason Ren <40999116+jasonren0403@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:22:47 +0800 Subject: [PATCH 2/3] Apply suggestions from code review --- files/zh-cn/web/api/document/fullscreenerror_event/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/zh-cn/web/api/document/fullscreenerror_event/index.md b/files/zh-cn/web/api/document/fullscreenerror_event/index.md index 1d2cccfe941cb6..5b107e70202a33 100644 --- a/files/zh-cn/web/api/document/fullscreenerror_event/index.md +++ b/files/zh-cn/web/api/document/fullscreenerror_event/index.md @@ -35,7 +35,7 @@ onfullscreenerror = (event) => {}; const requestor = document.querySelector("div"); function handleError(event) { - console.error("an error occurred changing into fullscreen"); + console.error("切换至全屏模式时发生错误"); console.log(event); } From 2dbdbe05dd75bf64eb8e17ae7cd181040f31e170 Mon Sep 17 00:00:00 2001 From: A1lo Date: Thu, 30 Nov 2023 21:59:43 +0800 Subject: [PATCH 3/3] Update files/zh-cn/web/api/document/fullscreenerror_event/index.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- files/zh-cn/web/api/document/fullscreenerror_event/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/zh-cn/web/api/document/fullscreenerror_event/index.md b/files/zh-cn/web/api/document/fullscreenerror_event/index.md index 5b107e70202a33..0140e24fc1afd5 100644 --- a/files/zh-cn/web/api/document/fullscreenerror_event/index.md +++ b/files/zh-cn/web/api/document/fullscreenerror_event/index.md @@ -59,4 +59,4 @@ requestor.requestFullscreen(); - {{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) +- [全屏 API 使用指南](/zh-CN/docs/Web/API/Fullscreen_API/Guide)