Requesting full screen refreshes data (html canvas) in object tag

若如初见. 提交于 2019-12-10 11:28:12

问题


I have a button on the view page that makes the object tag with id game full screen.

view.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);
}
}

The Problem

When the button fullscreen is clicked, it works fine and makes the game full screen BUT it refreshes it. So, if the user is midway in a game on level 2 and decides to go fullscreen, it restarts the game (loads the object again).


回答1:


I guess you are experiencing this on Chrome or other Webkit/Blink browser?

They have a weird behavior regarding <object>, where they unload its content when the element is not in the document anymore (or even just with style=display:none;...

That would make sense it fires here too since the element is actually detached from the active document.

Not much you can do I guess, while you may want to file a bug report, I would strongly suggest you try from an <iframe> instead, which doesn't suffer from this few years old bug...

Ps: it's data="url for <object>, not src="..



来源:https://stackoverflow.com/questions/52374155/requesting-full-screen-refreshes-data-html-canvas-in-object-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!