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

256
Vistas
How to get the height of an Iframe after writing to its content

I am writing the content of a textarea to an iFrame and so I need to set the height of the element on the parent page to display it properly:

  const $iFrames = $('iframe');

  function iframeLoaded(iFrameID) {
    const iFrame = document.getElementById(iFrameID);
    if (iFrame) {
      const height = `${iFrame.contentWindow.document.body.scrollHeight}px`;
      iFrame.height = '';
      iFrame.height = height;
      console.log('height:', height);
    }
  }

  $iFrames.each((i, frame) => {
    const $frame = $(frame);
    const ta = $frame
      .next('textarea');

    const doc = $(frame)[0].contentWindow.document;
    doc.open();
    doc.write(ta.val());
    doc.close();
    iframeLoaded($frame.attr('id'));
  });

However, in this example the height const is always 0, but the content is loaded correctly. Where am I going wrong?

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