[color=red][b]方法一[/b][/color] [size=large]在父页面写入js方法setHeight,iframe加载子页面时,子页面加载父页面方法setHeight.[color=red]self.parent.setHeight();[/color][/size]
]
function setHeight(){ var mainObj = document.getElementById("main"); var d_height=mainObj.contentDocument.body.clientHeight; if(d_height<230){ d_height=230; } mainObj.height=d_height+"px"; }
[color=red][b]方法二[/b][/color] [size=large] 父页面写入js方法SetCwinHeight,在iframe中使用onload属性加载方法SetCwinHeight. ([color=red]οnlοad="SetCwinHeight(this)"[/color])[/size]。
function SetCwinHeight(obj) { var cwin=obj; if (document.getElementById) { if (cwin && !window.opera) { if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight) cwin.height = cwin.contentDocument.body.offsetHeight + 20; //FF NS else if(cwin.Document && cwin.Document.body.scrollHeight) cwin.height = cwin.Document.body.scrollHeight + 10;//IE } else { if(cwin.contentWindow.document && cwin.contentWindow.document.body.scrollHeight) cwin.height = cwin.contentWindow.document.body.scrollHeight;//Opera } }
}
|