我在与父/容器页面相同的域/协议(protocol)内的 iframe 中加载 aspx 网页。 Iframe 中的内容有时比 iframe 本身更高。我不想在我的 Iframe 上显示滚动条。
我需要根据 iframe 将包含的 aspx 页面内的包装器“div”标记调整 iframe 的高度。 下面是我为实现此目的而编写的 jquery:
$("#TB_window", window.parent.document).height($("body").height() + 50);
'TB_window' - 包含 Iframe 的 div。
'body' - iframe 中 aspx 的 body 元素。
此脚本附加到 iframe 内容。我从父页面获取 TB_window 元素。 虽然这在 Chrome 上运行良好,但 TB_window 在 Firefox 中崩溃了。 我真的很困惑/不知道为什么会这样。
任何人都可以就我如何更好地处理这种情况提供任何建议吗? 非常感谢您的帮助 谢谢
最佳答案
你必须在你的 iframe 上使用管理一些事件
<iframe id="iframe" src="xyz" onload="FrameLoad(this);"
onresize="FrameLoad(this);" scrolling="no" frameborder="0">
</iframe>
function FrameLoad(ctrl) {
var the_height = ctrl.contentWindow.document.body.scrollHeight;
$(ctrl).height(the_height)
}
也用于跨浏览器
document.domain = document.location.hostname;
在父页面和子页面中
关于javascript - 如何根据元素高度动态调整 iframe 高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155634/