Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda