Fw: [問題] iframe 自動調整高度 (chrome失效) 解決
※ [本文轉錄自 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)
→
02/05 09:40, , 1F
02/05 09:40, 1F
→
02/05 09:41, , 2F
02/05 09:41, 2F
※ 編輯: sin282 來自: 218.210.231.212 (02/05 09:44)