Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

iframe高度自适应问题

下面是主页面的内容:

        <script type="text/javascript">
            function changeFrameHeight(){
                var ifm= document.getElementById("iframepage");
                ifm.height=document.body.clientHeight + 50;
            }
            window.onresize=function(){  
                 changeFrameHeight();
            } 
        </script>
        <div id="tt">
            <div title="首页">
                <iframe src="page/home.html" id="iframepage"  onload="changeFrameHeight()"  style="width:100%;" scrolling="no" frameborder="0"></iframe>
            </div>
        </div>

当页面缩小时,home.html内容不能全部显示出来,应该怎么更改?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

<script type="text/javascript">

function changeFrameHeight(){
  setTimeout(function(){
    var iFrameID = document.getElementById('iframepage');
    if(iFrameID) {
      iFrameID.height = "";
      iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
    }   
  },300)
}
window.onresize=function(){  
  changeFrameHeight();
} 

</script>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...