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

261
Views
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
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!