admin管理员组文章数量:1402902
I have a dashboard that updates every 5 seconds, and it's displayed on a TV. I implemented a fullscreen toggle button using JavaScript, but every time the page refreshes or the content updates (using location.reload()
or fetch()
), the page exits fullscreen mode. This is problematic because I need the fullscreen mode to stay active during these automatic updates, without the need for manual intervention.
The main issue is that when the content is updated or the page is refreshed, the fullscreen state is lost, even though the content is updated dynamically.
I tried using localStorage
to store the fullscreen state and also used fetch()
to update the content dynamically without reloading the page. Here's the code I’m using to toggle fullscreen:
<script>
document.getElementById("botao").addEventListener("click", function() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
localStorage.setItem("fullscreen", "true");
} else {
document.exitFullscreen();
localStorage.setItem("fullscreen", "false");
}
});
// Atualiza a página a cada 5 segundos sem sair do fullscreen
setTimeout(function() {
if (localStorage.getItem("fullscreen") === "true") {
location.reload();
setTimeout(() => {
document.documentElement.requestFullscreen();
}, 500);
} else {
location.reload();
}
}, 5000);
</script>
I expected that after the content was updated or the page refreshed, the fullscreen mode would remain active, preserving the state even during content changes. However, the fullscreen mode is lost after each update or refresh.
本文标签:
版权声明:本文标题:How to keep fullscreen mode active on a TV dashboard that updates every 5 seconds in JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744385098a2603700.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论