js让iframe高度自动

时间:2021-07-10 09:36:14

HTML:

<iframe  id="yb_if"   width="940px"   src="连接" frameborder=0 allowfullscreen></iframe>

JS:

//自动同步iframe高度

function reinitIframe(){
var iframe = document.getElementById("yb_if");
try{
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
}catch (ex){
}
}
window.setInterval("reinitIframe()", 200);