創(chuàng )建高度動(dòng)態(tài)變化的Iframe
iframe,尤其是不帶邊框的iframe因為能和網(wǎng)頁(yè)無(wú)縫的結合從而不刷新頁(yè)面的情況下更新頁(yè)面的部分數據成為可能,可是iframe的大小卻不像層那樣可以“伸縮自如”,所以帶來(lái)了使用上的麻煩,給iframe設置高度的時(shí)候多了也不好,少了更是不行,現在,我終于知道了讓iframe動(dòng)態(tài)體調整高度的方法,主要是以下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>
這樣使用效果確實(shí)不錯
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。