gpt4 book ai didi

javascript - 无法在 'requestFullScreen' : API can only be initiated by a user gesture 上执行 'Element'

转载 作者:太空狗 更新时间:2023-10-29 13:51:05 27 4
gpt4 key购买 nike

<分区>

我想让我的 HTML5 游戏在启动时变成原生全屏。当我通过单击按钮执行此操作时,它会全屏显示。但是当我使用 window.onload 使其全屏加载时,它会在控制台上回复 Failed to execute 'requestFullScreen' on 'Element': API can only be initiated by a user gesture。我正在使用 Chrome 。有解决方法吗?

我的代码:

    <!DOCTYPE html>
<html>
<head>
<script>
window.onload = openfullscreen();

function launchIntoFullscreen(element) {
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}

function openfullscreen() {

launchIntoFullscreen(document.documentElement);
}

function exitFullscreen() {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
window.close();
}

function fix() {
var screenwidth = screen.width;
var screenhei = screen.height;
document.getElementById('ifam').width = screenwidth;
document.getElementById('ifam').height = screenhei;
}
</script>
<style>
#ifam {
position:fixed;
left:0%;
top:0%;
z-index:-1;
}
#fullscreen {
position:fixed;
left:0%;
top:0%;
z-index:1;
}
</style>
</head>
<body onload="fix()">
<div id="fullscreen">
<button onclick="openfullscreen()">Open</button>
<button onclick="exitFullscreen()">Exit</button>
</div>
<iframe id="ifam" src="lchosser.html"></iframe>
</body>
</html>

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com