追求永无止尽

-- Ж飞羽忘寒Ж

导航

iframe自适应高度

<script type="text/javascript">
        function fit(){
            var frameWin = document.getElementById("MainForm");
            var frameBox = document.getElementById("ifmain");
           var newHeight;
           if (frameWin.Document){
               newHeight = frameBox.Document.body.scrollHeight + 20 + "px";
           }else{
                newHeight = frameBox.contentDocument.body.scrollHeight + 20 + "px";
           }
           frameBox.style.height = newHeight;
          }
    </script>

<body onload="fit();" onResize="fit();">

<form id="MainForm" runat="server">

<iframe id="ifmain" frameborder="0" width="100%" height="100%" marginwidth="0" onload="fit();" src="test.html"></iframe>

</form>

</body>

posted on 2010-01-26 08:51  Ж飞羽忘寒Ж  阅读(260)  评论(0)    收藏  举报