gpt4 book ai didi

javascript - 带内容加载的 Iframe

转载 作者:行者123 更新时间:2023-11-28 02:43:40 26 4
gpt4 key购买 nike

这是我在 StackOverflow 上的第一个问题,非常感谢所有社区。我目前正在尝试解决一个问题,但找不到任何解决方案:

我想在 Iframe 中显示内容,它必须自动调整大小(高度)

目前,一切都按计划进行,除了一件事情:当我进入页面时,iframe 内容已正确加载,但 iframe 的大小不正确。我必须刷新一次,然后它才会是正确的尺寸。这是我的代码:

<script>
function resizeIframe(obj) {
obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
obj.style.height = 0;
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
</script>

<iframe frameborder="0" width="1000" scrolling="no" onload="resizeIframe(this)" src="/myurl.url"></iframe>

任何帮助将不胜感激!

谢谢

最佳答案

您可以告诉它在加载后刷新页面,或者为您的函数设置一个超时设置以等待它运行。

您是否尝试过将函数添加到 document.ready(function() {});

关于javascript - 带内容加载的 Iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42484809/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com