This snippet gets the height of an iframe’s content and then resizes the height of the iframe to match.
Assume that frame
represents the iframe element.
frame.addEventListener('load', function() {
// Get the height of the content
const height = frame.contentDocument.body.scrollHeight;
// Set the height of iframe
frame.setAttribute('height', `${height}px`);
});