
スクロールバー無しでiframeを表示させたいときなどに。lazyload(+lazysizes)との併用も可。
HTML
<iframe src="path/to/file" loading="lazy" id="write-your-id"></iframe>
JavaScript
const yourVar = document.querySelector('#write-your-id');
yourVar.addEventListener('load', function() {
yourVar.style.height = yourVar.contentWindow.document.body.scrollHeight + 'px';
});
コメント欄