Ifram框架适应高度 javascript实现

<script type="text/javascript">

//框架自应用高度

function dyniframesize(down) {

var pTar = null;

if (document.getElementById) {

pTar = document.getElementById(down);

}

else {

eval('pTar = ' + down + ';');

}

if (pTar && !window.opera) {

//begin resizing iframe

pTar.style.display = "block"

if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {

//ns6 syntax

pTar.height = pTar.contentDocument.body.offsetHeight + 20;

pTar.width = pTar.contentDocument.body.scrollWidth + 20;

}

else if (pTar.Document && pTar.Document.body.scrollHeight) {

//ie5+ syntax

pTar.height = pTar.Document.body.scrollHeight;

pTar.width = pTar.Document.body.scrollWidth;

}

}

}

</script>

在Ifram处设置:

<iframe style="vertical-align: top; padding-left: 0px; height: 447px; width:720px;

background-color: #EAEEED" onload="javascript:dyniframesize('WorkSpace');" >

</iframe>

上面这种方法我是在http://bbs.51aspx.com/showtopic-2263.html看来的,但是当你对这个ifram框进行设置了height时,那么当你的内容超过height时就不能进行拉申了;

以下这种方法他不受你所设置的height的限制:

<script type="text/javascript">

if (window != top) top.location = window.location;

// 调整 Table DesktopFrame 的大小,以使 IFrame WorkSpace 不出现滚动条

function WorkSpaceLoad() {

var h = WorkSpace.document.body.scrollHeight;

if (h > 450)

parent.DesktopFrame.height = h;

parent.document.all.WorkSpace.style.height = h;

}

</script>

在有框架的表格上设置:

<table width="100%" >

<tr>

<td>

<iframe style="vertical-align: top; padding-left: 0px; width: 725px;

background-color: #EAEEED" >

</iframe>

</td>

</tr>

</table>

但是这两种方法都受到了首次宽度的限制,就是说当你在同一个页面时,有不同的操作,第一个操作显示的内容少,第二个操作显示的内容多;如果说你是先操作第一个,那么当你操作第二个时页面的框架是不会自动拉申的;此问题已经困了很久了,如有高手知道怎么处理请分享一下,非常的感谢,,,,