JavaScript中的document.onfullscreenerror


本文作者: jsweibo

本文链接: https://jsweibo.github.io/2019/11/14/JavaScript%E4%B8%AD%E7%9A%84document-onfullscreenerror/

摘要

本文主要讲述了:

  1. 触发时机

正文

触发时机

目标元素的requestFullscreen()调用失败时,将会触发:

  1. 目标元素的fullscreenerror事件
  2. 包含目标元素的documentfullscreenerror事件

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<button id="foo" type="button">Fullscreen Display</button>
<script>
const foo = document.querySelector('#foo');

foo.requestFullscreen();

foo.addEventListener('fullscreenerror', function (event) {
console.log(event);
});

document.addEventListener('fullscreenerror', function (event) {
console.log(event);
});
</script>
</body>
</html>

参考资料

本文作者: jsweibo

本文链接: https://jsweibo.github.io/2019/11/14/JavaScript%E4%B8%AD%E7%9A%84document-onfullscreenerror/


本文对你有帮助?请支持我


支付宝
微信