iframe自适应高度

原文地址1
地址2
<iframe id="frame_content" src="iframe_b.html" scrolling="no" frameborder="0" 
onload="this.height=100"></iframe> 
<script type="text/javascript"> 
var cbHeight = 0;
var cdHeight = 0;
function reinitIframe(){ 
var iframe = document.getElementById("frame_content"); 
try{ 
var bHeight = iframe.contentWindow.document.body.scrollHeight; 
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; 
if (bHeight != cbHeight || dHeight != cdHeight) {
	iframe.height = 100;
	bHeight = iframe.contentWindow.document.body.scrollHeight;
	dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
	iframe.height=Math.max(bHeight, dHeight);
	cbHeight = bHeight;
	cdHeight = dHeight;
}
}catch (ex){} 
} 
window.setInterval(reinitIframe, 200); 
</script> 

你可能感兴趣的:(iframe)