【发布时间】:2011-02-10 16:45:42
【问题描述】:
<iframe name="asdf" id="asdf" onload="change_height(this)" src="asdf.jsp" width="250" scrolling="no" frameborder="0"></iframe>
function change_height(iframe) {
if (document.all) {
// IE.
ieheight = iframe.document.body.scrollHeight;
iframe.style.height = ieheight;
} else {
// Firefox.
ffheight= iframe.contentDocument.body.offsetHeight;
iframe.style.height = ffheight+ 'px';
}
}
ieheight 是在 IE7 中运行时实际高度的两倍;没有在IE6上测试过。如果我使用 scrollHeight 或 offsetHeight,它的值是相同的。
这是 Firefox 中的正确高度。
在我只通过将 IE 值 /2 来修补之前,这样做的正确方法是什么?
【问题讨论】:
标签: javascript iframe cross-browser