作者sin282 (@兴...)
看板Web_Design
标题Fw: [问题] iframe 自动调整高度 (chrome失效)
时间Tue Feb 5 08:50:18 2013
※ [本文转录自 Ajax 看板 #1H3uROm- ]
作者: sin282 (@兴...) 看板: Ajax
标题: [问题] iframe 自动调整高度 (chrome失效)
时间: Mon Feb 4 18:00:52 2013
google了如何自动调整iframe高度的方法,确定以下语法在ie & FF可行
但使用Chrome测试时,只有高度变高时才会改变
如果现在改变的iframe高度低於改变前的,则无效果,会留一片白底~
alert进行测试,发现 iframeid.contentDocument.body.offsetHeight
只会在变高时改变~
请问一下有办法高度缩小时让Chrome也即时抓取iframe的高度吗? 感恩
Father.htm 里头有个iframe ID="content"
Father.htm 里有四五个按钮点击後连结会反应在content里.
iframe的onload="SetCwinHeight();"
<script>
function SetCwinHeight()
{
var iframeid=document.getElementById("content"); //iframe id
if (document.getElementById)
{
if (iframeid && !window.opera)
{
if (iframeid.contentDocument &&
iframeid.contentDocument.body.offsetHeight)
{
//ff
iframeid.height=0; // 加了就解决了
iframeid.height = iframeid.contentDocument.body.offsetHeight;
}else (iframeid.Document && iframeid.Document.body.scrollHeight)
{
//ie
iframeid.height = iframeid.Document.body.scrollHeight;
}
}
}
}
</script>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.210.231.212
※ 编辑: sin282 来自: 218.210.231.212 (02/05 08:47)
※ 编辑: sin282 来自: 218.210.231.212 (02/05 08:48)
※ 发信站: 批踢踢实业坊(ptt.cc)
※ 转录者: sin282 (218.210.231.212), 时间: 02/05/2013 08:50:18
※ 编辑: sin282 来自: 218.210.231.212 (02/05 09:05)
※ 编辑: sin282 来自: 218.210.231.212 (02/05 09:15)
1F:→ sin282:解决了.... 02/05 09:40
2F:→ sin282:多加一行 iframeid.height=0; 02/05 09:41
※ 编辑: sin282 来自: 218.210.231.212 (02/05 09:44)