Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!