框架工作,但高度总是增加

Iframe working but Height always increase

本文关键字:增加 高度 工作 框架      更新时间:2023-09-26

你好,经过几个小时的搜索,我发现了一个脚本,适用于我的iframe,除了一个小问题,它永远不会停止,它增加高度没有停止…下面是代码我在我的页面上添加了这个脚本,我想要iframe

<script>
  function alertsize(pixels){
    pixels+=0;
    document.getElementById('myiframe').style.height=pixels+"px";
  }
</script>
<script type="text/javascript">
  var myHeight = 0;
  setInterval(function(){
    if(myHeight != document.body.scrollHeight){
      myHeight = document.body.scrollHeight;
      parent.alertsize(myHeight);
    }
  },500);
</script>

这里是iframe:

<iframe id="myiframe" src="http://www.altasoft.gr/hermes/index.html"
        name="myiframe" width="100%" height="100%" scrolling="no"
        frameborder="0"></iframe>

问题是您的标记中的height="100%"。将其更改为固定像素值,脚本将开始工作。所以把height="100%"改成height="1"或者别的什么,具体值不重要