我在查看页面上有一个按钮,可以使带有 id 游戏的对象标签全屏显示。
视图.html
<object id="game" src="url/file.html"></object>
<span onclick="fullScreen()"></span>
main.js
function fullScreen() {
var elem = document.getElementById("game");
if (elem.requestFullscreen) {
elem.requestFullscreen();
document.addEventListener('fullscreenchange', fullScreenExit, false);
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
document.addEventListener('fullscreenchange', fullScreenExit, false);
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
document.addEventListener('mozfullscreenchange', fullScreenExit, false);
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
document.addEventListener('webkitfullscreenchange', fullScreenExit, false);
}
}
问题
单击该按钮时fullscreen
,它可以正常工作并使游戏全屏显示,但会刷新它。因此,如果用户在关卡 2 的游戏中途并决定进入全屏模式,它会重新启动游戏(再次加载对象)。