const iframe = document.getElementById('iframeId');
iframe.onload =function(){
try{const doc = iframe.contentDocument||iframe.contentWindow.document;const body = doc.body;const html = doc.documentElemet;const height = Math.max(body.scrollHeight ,body.offsetHeight,html.scrollHeight,html.offsetHeight
) ;
iframe.style.height=height+'px';}.catch(e){
console.log('无法获取iframe内容高度',e)
}
}