白桦的天空

第一次的心动,永远的心痛!
  首页  :: 新随笔  :: 联系 :: 管理

iframe自动适应付窗口的大小变换

Posted on 2008-11-10 13:22  白桦的天空  阅读(407)  评论(0编辑  收藏  举报

index.html---

 

<html><title></title><body onload="javascript:{dyniframesize('myTestFrameID');}" onresize="javascript:{dyniframesize('myTestFrameID');}">
ddddddddddddddddddddddddd<br />
dddddddddddddddddddddddd<br />ddddddddddddddddddddddddd<br />
dddddddddddddddddddddddd<br />ddddddddddddddddddddddddd<br />
dddddddddddddddddddddddd<br />ddddddddddddddddddddddddd<br />
dddddddddddddddddddddddd<br />
<script language="Javascript">
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
//extra height in px to add to iframe in FireFox 1.0+ browsers
var FFextraHeight=getFFVersion>=0.1? 16 : 0

function dyniframesize(iframename) {
  var pTar = null;
  if (document.getElementById){
    pTar = document.getElementById(iframename);
  }
  else{
    eval('pTar = ' + iframename + ';');
  }
  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+FFextraHeight;
    }
    else if (pTar.Document && pTar.Document.body.scrollHeight){
      //ie5+ syntax
     // pTar.height = pTar.Document.body.scrollHeight;
   //  if(pTar.Document.body.scrollHeight>document.body.clientHeight)
   //  pTar.height = document.body.clientHeight-340;
  //else
  //pTar.height = pTar.Document.body.scrollHeight;
 // alert(document.body.scrollHeight+240);
 // alert(document.body.clientHeight+1);
 // alert(pTar.Document.body.scrollHeight);
  if(pTar.Document.body.scrollHeight+240<document.body.clientHeight+1)
  pTar.height = document.body.clientHeight-240;  
  else
  pTar.height = pTar.Document.body.scrollHeight;
    }
  }
}
</script>
 
<iframe id="myTestFrameID"
marginwidth=0 marginheight=0 frameborder=0
scrolling=no src="content2.html"
width=200 height=100></iframe>
kkkkkkkkkkkkkkkkkkkk<br />
kkkkkkkkkkkkkkkkkkkk<br />
kkkkkkkkkkkkkkkkkkkk<br />
kkkkkkkkkkkkkkkkkkkk<br />
kkkkkkkkkkkkkkkkkkkk<br />
<script>

</script>
</body>
</html>