0

In the iframe element I added a src attribute and when it loads, the function will be called and in this case the document.body refers to the main body.

I have already tried using $(document).ready(function() {}) and document.body[1], without any success.

<iframe  id="inlineFrameExample" class="iframeDynamic" title="Inline Frame Example" width="300" name="myFrame" src="http://www.nu.nl" onload="resizeIframe(this)">
<html>
    <head></head>
    <body></body>
</html>

function resizeIframe() {

    let test = document.body;

    console.log(test);

    // What's the page height?
    var height = document.body.scrollHeight;

    // Going to 'pipe' the data to the parent through the helpframe..
    var pipe = document.getElementById('inlineFrameExample');

    // Cachebuster a precaution here to stop browser caching interfering
    newSource = pipe.src + '?height='+height+'&cacheb='+Math.random();
    pipe.style.height = height + 'px';
}

In my care the document.body will not refer to the right body element. Also keep in mind this is a dynamically added element. I want to select that and then get the specific height of that body element inside the iframe.

SaschaM78
  • 4,376
  • 4
  • 33
  • 42
frontend
  • 137
  • 1
  • 11
  • is the iframe the same domain than the parent? if not, you can't acces it. Check this answer https://stackoverflow.com/questions/729577/can-javascript-access-iframe-elements-from-the-parent-page – Alex Angelico Apr 30 '19 at 13:31
  • And this one if it's about sizing https://stackoverflow.com/questions/7532315/cross-domain-iframe-resizer-using-postmessage – Wiktor Zychla Apr 30 '19 at 13:32

0 Answers0