实现iFrame自适应高度,原来很简单!(绝对能用)

<iframe id="iFrame1" name="iFrame1" width="100%" onload="this.height=iFrame1.document.body.scrollHeight" frameborder="0" src="index.htm"></iframe>
看到了吧,关键就在于onload="this.height=iFrame1.document.body.scrollHeight"!
 
下边这个正确~~~~~~~~~~~~~

<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>

posted @ 2008-02-25 19:06  looping  阅读(467)  评论(1编辑  收藏  举报