【发布时间】:2013-10-12 18:16:50
【问题描述】:
我知道有很多关于调整iframe 大小的帖子,但我发现的只是这段代码:
<script type="text/javascript" language="JavaScript">
<!--
function autoResize(id) {
var newheight;
var newwidth;
if (document.getElementById) {
newheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
newwidth = document.getElementById(id).contentWindow.document.body.scrollWidth;
}
document.getElementById(id).height = (newheight);
document.getElementById(id).width = (newwidth);
};
//-->
</script>
这是示例标记代码:
<a href="index.php" target="content">Home</a>
<a href="profile.php" target="content">Profile</a>
<iframe src="index.php" name="content" height="500px" width="100%" id="Main_Content" onload="autoResize('Main_Content');"></iframe>
上面的代码可以正常工作,但我有一个问题。考虑这种情况:
index.php page height is 800px
和
profile.php page height is 1200px
当我单击指向index.php 页面的链接时,iframe 会调整为800px,然后我单击指向profile.php 页面的链接,iframe 会调整为1200px 但这是我的问题,当我再次单击指向index.php 的链接时,该链接的高度小于profile.php 页面,iframe 没有调整大小,也没有调整800px 的高度,这会导致@ 的内容下方有多余的空间987654335@ 看起来不太好,我在增加 iframe 高度时没有问题,但在缩小它时遇到了一些麻烦,有人可以帮我吗?任何帮助表示赞赏。谢谢!
【问题讨论】:
-
home.php和index.php一样吗?
-
哇,对不起,是的,它是一样的,只是一些错字。
-
跨浏览器的问题是否相同,还是仅针对特定浏览器?
-
跨浏览器的同样问题 :(
-
您能否通过警报('hi')进行验证;在您第二次点击主页时实际上触发的自动调整大小功能中?我最好的猜测是 onload 事件没有第二次触发。
标签: javascript jquery html iframe