Failed to execute 'exitFullscreen' on 'Document': Document not active我没有进入全屏模式确通过了this.FullScreen判断
时间: 2024-01-07 12:02:59 浏览: 55
如果您没有进入全屏模式但仍然遇到 "Failed to execute 'exitFullscreen' on 'Document': Document not active" 错误,则可能是因为您在调用 exitFullscreen() 方法之前没有检查当前页面是否处于全屏模式。您可以在调用该方法之前检查 document.fullscreenElement 属性是否为 null,如果为 null,则表示页面当前不处于全屏模式,此时您可以跳过退出全屏模式的操作。因此,您可以在执行 exitFullscreen() 方法之前添加以下代码:
```
if (document.fullscreenElement !== null) {
document.exitFullscreen();
}
```
这将确保页面在进入全屏模式后再退出全屏模式时不会出现错误。
相关问题
TypeError: Failed to execute 'exitFullscreen' on 'Document': Document not active at main.js:117
这个错误通常是因为在尝试退出全屏模式时,文档不处于活动状态。这可能是因为在退出全屏模式之前,文档已经失去了焦点或被隐藏了。你可以在调用 `exitFullscreen()` 方法之前确保文档处于活动状态,例如:
```
if (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {
// 确保文档处于活动状态
document.activeElement.blur();
// 退出全屏模式
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
```
这段代码会先检查文档是否处于全屏模式,如果是,则让当前的焦点元素失去焦点,确保文档处于活动状态,然后再尝试退出全屏模式。
TypeError: Failed to execute 'exitFullscreen' on 'Document': Document not active
这个错误通常是因为你尝试在一个不支持全屏模式的文档中调用 exitFullscreen 方法。请确保你在支持全屏模式的文档中调用此方法。另外,请注意 exitFullscreen 方法只能在全屏模式下调用,如果你的文档当前不在全屏模式下,也会出现类似的错误。你可以通过检查 document.fullscreenElement 是否为空来判断当前是否在全屏模式下。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)