Resize an iframe to fit its content

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`);
});

More

Previous
Position an element absolutely to another element
Next
Resize columns of a table