【发布时间】:2013-11-19 19:09:46
【问题描述】:
我有一个包含多个页面的脚本的 iframe,我想根据内容高度自动调整此 iframe 的高度。当我加载第一页时它可以正常工作,但是当我切换到另一个页面时,会再次调用该函数,但高度是相同的,即使每个页面上的内容高度不同。
javascript函数:
function autoResize(id){
var newheight;
if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
}
document.getElementById(id).height= (newheight) + "px";
}
还有我的 iframe:
<iframe id="iframe" src="myScript" width="950px" onLoad="autoResize('iframe');"></iframe>
当我在使用contentWindow.document.body.scrollHeight 设置后添加alert(newheight) 时,我会在每一页上收到警报,但高度始终相同。
还有其他方法可以获取当前 iframe 内容高度吗?
【问题讨论】:
标签: javascript iframe