【发布时间】:2010-12-18 06:05:01
【问题描述】:
我正在使用以下脚本自动调整 iframe 高度。
function autoIframe(frameId) {
try {
frame = document.getElementById(frameId);
innerDoc = (frame.contentDocument) ?
frame.contentDocument : frame.contentWindow.document;
objToResize = (frame.style) ? frame.style : frame;
objToResize.height = innerDoc.body.scrollHeight + 10 + 'px';
}
catch (err) {
window.status = err.message;
}
}
我在前两个标签(myiframe1 和 myiframe2)中有三个 jquery 标签和 iframe
我在加载 iframe 时调用上述代码。
<iframe id="myiframe1" width="100%" onload="autoIframe('myiframe1');"
scrolling="auto" frameborder="0" src="mypath1">
</iframe>
<iframe id="myiframe2" width="100%" onload="autoIframe('myiframe2');"
scrolling="auto" frameborder="0" src="mypath2">
</iframe>
这在谷歌浏览器和 IE8 中运行良好。 但在 Firefox 中,第一个选项卡(可见选项卡)中的 iframe 具有根据内容的高度,而第二个选项卡中的 iframe 未设置正确的高度。第二个标签的高度设置为 10px。
这里可能有什么问题?
【问题讨论】: