如何让iframe自适应浏览器高度?

cai272646063 2009-05-01 03:14:18
如题,
...全文
224 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cai272646063 2009-05-01
  • 打赏
  • 举报
回复
<iframe id="contentFrame" name="contentFrame" style="height:100%;" src="Menu.aspx" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"> </iframe>
这样就行了,不用JS
cai272646063 2009-05-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhanglei_love2008 的回复:]
<head runat="server">
<title id="pageTitle"> </title>

<script type="text/javascript">
function autoHeight()
{
var obj=window.frames["right"];
document.getElementById("right").height=obj.document.body.scrollHeight+20;
}
</script>

</head>
<body>
<iframe id="right" name="right" style="width: 800px;" frameborder="no"
scrolling="no" onload="autoHeight()"> </iframe>
</body>

[/Quote]

试了,不行。
蓝海D鱼 2009-05-01
  • 打赏
  • 举报
回复

为使iframe的高度能够自适应当前浏览器窗口的大小,在window.onresize时,对iframe的高度进行设置。

<div id="topbar"></div>
<iframe id="contentFrame" name="contentFrame" frameborder="0" hideFocus style="width:100%;height:100%;" src="welcome.jsp" scrolling="auto"></iframe>
<script type="text/javascript">
(window.onresize = function()
{
var docH= parseInt( document.body.clientHeight,10);
var minHeight=101;
var h=docH-(document.getElementById('topbar').offsetHeight+18);
h = h<minHeight ? minHeight : h;
document.getElementById('contentFrame').style.height=h+'px';
}
)();
</script>
中年秃头大叔 2009-05-01
  • 打赏
  • 举报
回复
<head runat="server">
<title id="pageTitle"></title>

<script type="text/javascript">
function autoHeight()
{
var obj=window.frames["right"];
document.getElementById("right").height=obj.document.body.scrollHeight+20;
}
</script>

</head>
<body>
<iframe id="right" name="right" style="width: 800px;" frameborder="no"
scrolling="no" onload="autoHeight()"></iframe>
</body>

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧