創建高度動態變化的Iframe
iframe,尤其是不帶邊框的iframe因為能和網頁無縫的結合從而不刷新頁面的情況下更新頁面的部分數據成為可能,可是iframe的大小卻不像層那樣可以“伸縮自如”,所以帶來了使用上的麻煩,給iframe設置高度的時候多了也不好,少了更是不行,現在,我終于知道了讓iframe動態體調整高度的方法,主要是以下JS函數:
function SetCwinHeight()
{
var cwin=document.getElementById("cwin"
;
if (document.getElementById)
{
if (cwin && !window.opera)
{
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
cwin.height = cwin.contentDocument.body.offsetHeight;
else if(cwin.Document && cwin.Document.body.scrollHeight)
cwin.height = cwin.Document.body.scrollHeight;
}
}
}
最后,加入iframe,不能丟掉onload屬性,當然了,id也必須也函數中的cwin匹配
<iframe width="778" align="center" height="200" id="cwin" name="cwin" onload="Javascript:SetCwinHeight()" frameborder="0" scrolling="no"></iframe>
這樣使用效果確實不錯
本站僅提供存儲服務,所有內容均由用戶發布,如發現有害或侵權內容,請
點擊舉報。