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

232
Visualizações
Script Produces "Uncaught TypeError: Cannot read properties of null (reading 'scrollHeight')" When Iframe is Reloaded

I added the highlighted script to my PHP page's header to automatically adjust iframe size to iframe contents; the script is activated w/ <script>sizeit("#frame_id");</script>, and the results are as expected / it works well.

However, on iframe reload (w/ a "right-click / Reload iframe" selection within the iframe) the script produces the following error: "Uncaught TypeError: Cannot read properties of null (reading 'scrollHeight')"

It seems scrollHeight isn't available on iframe reload.

<script>
function sizeit(id){
    let iframe = document.querySelector(id);

    iframe.addEventListener('load', function() {
        setInterval(function() {
            iframe.style.height = iframe.contentDocument.body.scrollHeight + 10 + 'px';
            iframe.style.width = 100 + '%';
        });
    });
}
</script>

Any thoughts on how to resolve this? The error message does not appear when the entire page is reloaded, only when an iframe is reloaded.

about 4 years ago · Juan Pablo Isaza
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