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

141
Views
I can't get scroll height of IFrame in HTML/JavaScript

I have a simple HTML code like this:

<!DOCTYPE html>
<html>
   </head>
   <script>
         function func() {
            var x = document.getElementById("frm").contentWindow.document;
            document.getElementById("val").innerHTML = "scrollHeight is: " + x.documentElement.scrollHeight;
        }
    </script>
   </head>
   <body>
        <button id="val" onclick="func()">getScrollHeight</button>
        <br>
        <br>
        <iframe id="frm" src="https://www.wikipedia.org/" width="100%"></iframe>
   </body>
</html>

I have a problem with above code:

When I clear the "src" attribute of IFrame(src="") and then click on the "getScrollHeight" button, it shows a number(in my browser it shows 150. The value is not important), But when I fill out the "src" attribute with a web address(for example src="https://www.wikipedia.org/") and then click on the button, it shows nothing. Why does this happen? Why can't I get the scroll height when the IFrame has a content?

My browser is chrome (also edge).

Thanks for any suggestion.

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!