function setIFrameHeight(iframe){
var ifm_content = document.getElementById("conFrame");
ifm_content.height = "500px";//默认设置为500px
var heightContent = "500px";
var subContent = document.frames ?document.frames["conFrame"].document : ifm_content.contentDocument;
if (iframe == "content") { //如果传入Ifame Id 等于content 重新给iframe赋值高度
heightContent =Math.max(subContent.body.scrollHeight, subContent.documentElement.scrollHeight);
ifm_content.height =heightContent;
}
}
实例说明:
我的Html中有一个Iframe 用法如下:
<iframeid="conFrame" src="a.html" frameborder="0"scrolling="no"
width="100%"height="500px" onload="setIFrameHeight('content');"></iframe>