![Resize an iframe to fit its content](https://javascriptsource.com/wp-content/uploads/2021/07/Resize-an-iframe-to-fit-its-content-702x526.jpg)
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`);
});