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.