我正在尝试在react中退出全屏,但是当我尝试下面的代码时,它会得到错误。
Failed to execute 'exitFullscreen' on 'Document': Document not active所以在搜索之后,我找到了使用fullScreenElement check,所以我用一个if条件包装了它,但是当前在chrome上,即使我单击exit按钮,它也不会执行任何操作。
function exitFull() {
if (
document.fullscreenElement ||
document.webkitFullscreenElement ||
document.mozFullScreenElement ||
document.msExitFullscreenElement
) {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
setIsFull(false);
}
}因为当我调试fullscreenElement时,它显示为null,如果我用document.fullscreen替换它,就会给出false,就像在docs中提到的那样,它被弃用了,所以我为什么要使用fullscreenElement?
这是调用此函数时获得所述错误的片段。
document.exitFullscreen();
Failed to execute 'exitFullscreen' on 'Document': Document not active知道怎么解决这个问题吗?
发布于 2022-08-22 03:02:24
我也遇到了同样的问题,我发现一个原因是exitFullscreen只能在全屏mode.Otherwise生效时才会收到错误:文档不活动
https://stackoverflow.com/questions/67407047
复制相似问题