Управление DOM с помощью JavaScript в современных браузерах и IE 11+
Предположим, что frame представляет элемент iframe.
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`);
});