Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
Nested Iframe doesn't have content after reload on Mozilla

I have this problem on Mozilla (worked perfectly on Chrome) where the nested Iframe doesnt have content after reload (only empty header and body tag)

Somehow you can click on the search bar and enter (instead of reload) to open again and all iFrame will load as intended

---------Working Snippet---------

https://codesandbox.io/s/determined-edison-9rwhwv?file=/index.html

Body index.html

<body>
    <div>Index</div>
    <iframe id="iframe"></iframe>
    <script>
        (function () {
            var b = document.getElementById("iframe");
            b.setAttribute("src", "iframe.html?" + Math.random() * 100);
        })();
        window.addEventListener('beforeunload', function (event) {
            console.log('I am the 1st one.');
        });
        window.addEventListener('unload', function (event) {
            alert('unLoad')
        });
    </script>
</body>

body iframe.html

<body>
    <header>
        IFRAME1
    </header>
    <iframe id="iframe2"></iframe>
    <script>
        (function () {
            var b = document.getElementById("iframe2");
            b.setAttribute("src", "iframe2.html?" + Math.random() * 100);
        })();
        window.addEventListener('beforeunload', function (event) {
            console.log('frame 1 before unload.');
        });
        window.addEventListener('unload', function (event) {
            console.log('frame 1 unload.');
        });
        window.addEventListener('pagehide', (event) => {
            if (event.persisted === true) {
                console.log('This page *might* be entering the bfcache.');
            } else {
                console.log('This page will unload normally and be discarded.');
            }
        });
    </script>
</body>

Body iframe2.html

<body>
    <header id="h2">
        this is iframe 2
    </header>
    <script src="iframe2.js"></script>
</body>

I read something about bfcache, which is why i tried to put unload event to negate bfcache.


Found this thread with help from zer00ne about mixed content Mixed Content warning on Chrome due to iframe src

But this seems to be a security issue to do

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I got it working by calling the function after load event

window.addEventListener('load', function () {
            function setIframe() {
                var b = document.getElementById("iframe");
                b.setAttribute("src", "iframe.html");
            }
            setIframe();
        })

Hope this helps anyone.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda