I have the following code, that checks the iFrame content width every 0.1 seconds. This code works, but I don't think it is best practice.
Here is my code
function iframeLoaded() {
var iFrameID = document.getElementById('appframe');
if (iFrameID)
{
iFrameID.height = '';
if (iFrameID.height != iFrameID.contentWindow.document.body.scrollHeight + 'px')
{
iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + 'px';
}
}
}
setTimeout(iframeLoaded, 100);
and the HTML
<iframe src='https://google.com' frameborder='0' scrolling='no' id='appframe' onload='iframeLoaded()'></iframe>
Would the best solution be to check if the iFrame height has changed every 0.1 seconds, and only then adapt the size of iframe height if a change has been noticed.
As now, the code is adapting the height, even if they detect no change in iFrame height.