There are plenty of examples showing how to dynamically set an iframe
's height to its content. This works perfect for me. The problem I'm now having is that the content can change size without triggering onload
(think hidden/expandable div
s).
Is there any way to detect when the size of the iframe
content has changed? This is on the same domain and no jQuery, please.
I would do this by polling regularly (maybe every 200 milliseconds, perhaps more often) using setInterval
. You could then compare the size of the content to what it was last time.
var iframe = document.getElementById('myIframe'),
lastheight;
setInterval(function(){
if (iframe.document.body.scrollheight != lastheight) {
// adjust the iframe's size
lastheight = iframe.document.body.scrollheight;
}
}, 200);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With