/html-dom /Basic
GitHub 4932★

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

See also

Follow me on and to get more useful contents.