主页面:
<iframe id="z" name="z" src="dj/_tbl.php?b=user_files" scrolling="no" frameborder="0" style="width:100%;" οnlοad="setIframeHeight()" ></iframe>
<SCRIPT type="text/javascript">
function getiframeDocumentPort (iframe) {
if(iframe.document.compatMode == "BackCompat") {
return {
width: iframe.document.body.scrollWidth,
height: iframe.document.body.scrollHeight
};
} else {
return {
width: Math.max(iframe.document.documentElement.scrollWidth,iframe.document.documentElement.clientWidth),
height: Math.max(iframe.document.documentElement.scrollHeight,iframe.document.documentElement.clientHeight)
}
}
}
// document.domain = "xphxcc.com";
function setIframeHeight() {
var iframe = document.getElementById('z');
if (iframe) {
iframe.style.height = "10em";
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
iframe.style.height = (getiframeDocumentPort(iframeWin).height)+"px";
}
};
window.οnresize=function(){
setIframeHeight();
}
</SCRIPT>
如果在iframe页内还有ajax动态更改页面高度的情况时,还需要在相应的js 内引用此function
<span οnclick="changeweb();">点击</span>
<SCRIPT type="text/javascript">
function changeweb() {
//...如果在此改变了网页内容
//刷新高度
parent.setIframeHeight();
}
</SCRIPT>