实现iFrame自适应高度

<script language="javascript" 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>

<iframe src ="/default2.aspx"  frameborder="0" marginheight="0" marginwidth="0"  frameborder="0" scrolling="auto" id="ifm" name="ifm"  onload="javascript:dyniframesize('ifm');"  width="100%">

</iframe>

--------------------------------------------------------------------------

<iframe id="iframe1" name="iframe1" width="100%" onload="this.height=iframe1.document.body.scrollHeight" frameborder="0" src="index.htm"></iframe>

posted @ 2011-02-25 13:44  盛行天宇  阅读(225)  评论(0编辑  收藏  举报