最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to keep fullscreen mode active on a TV dashboard that updates every 5 seconds in JavaScript? - Stack Overflow

programmeradmin7浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论