<script language='javascript' src='http://www.shiqiaotou.com/donetk/Header.js'></script>
<
IFRAME
id
="iframe1"
name
="iframe1"
marginWidth
="0"
marginHeight
="0"
frameBorder
="0"
scrolling
="no"
src
="a.aspx"
runat
="server"
></
IFRAME
>
function
dyniframesize(iframename)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
var pTar = null;
if (document.getElementById)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pTar = document.getElementById(iframename);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
else
{
eval('pTar = ' + iframename + ';');
}
if (pTar && !window.opera)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pTar.style.display="block"
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pTar.height = pTar.contentDocument.body.offsetHeight+10;
}
else if (pTar.Document && pTar.Document.body.scrollHeight)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pTar.width = pTar.Document.body.scrollWidth;
pTar.height = pTar.Document.body.scrollHeight;
}
}
}
在body里增加:
οnlοad="dyniframesize('iframe1')"
即可达到当我们打开default.aspx,使得a.aspx自适应大小。
还存在一个问题,当点击a.aspx里的按钮时,需要重新计算他的父页面中的iframe的大小,达到
刷新a.aspx时,页面依然自适应。
function
dyniframesize()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
var pTar = null;
if (document.getElementById)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//仅仅修改此句代码:
pTar = window.parent.document.getElementById("iframe1");
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
else
{
eval('pTar = ' + iframename + ';');
}
if (pTar && !window.opera)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pTar.style.display="block"
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pTar.height = pTar.contentDocument.body.offsetHeight+10;
}
else if (pTar.Document && pTar.Document.body.scrollHeight)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pTar.width = pTar.Document.body.scrollWidth;
pTar.height = pTar.Document.body.scrollHeight;
}
}
}
同样在a.aspx的body里加载这个函数。
οnlοad="dyniframesize()"
文章来源于 http://www.cnblogs.com/zhangzs8896 版权归原作者所有<script language='javascript' src='http://www.shiqiaotou.com/donetk/Footer.js'></script>
有时候会在页面里使用框架,但又不想叫它出现滚动条,这就用到了自适应。
架设default.aspx页面里使用了Iframe,它的ID: iframe1,src指向a.aspx
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
那么在default里使用如下脚本:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
在body里增加:
οnlοad="dyniframesize('iframe1')"
即可达到当我们打开default.aspx,使得a.aspx自适应大小。
还存在一个问题,当点击a.aspx里的按钮时,需要重新计算他的父页面中的iframe的大小,达到
刷新a.aspx时,页面依然自适应。
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
同样在a.aspx的body里加载这个函数。
οnlοad="dyniframesize()"
文章来源于 http://www.cnblogs.com/zhangzs8896 版权归原作者所有<script language='javascript' src='http://www.shiqiaotou.com/donetk/Footer.js'></script>