Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript I框架工作,但高度始终增加_Javascript_Iframe - Fatal编程技术网

Javascript I框架工作,但高度始终增加

Javascript I框架工作,但高度始终增加,javascript,iframe,Javascript,Iframe,你好,经过几个小时的搜索,我发现了一个适用于我的iframe的脚本。除了一个小问题,它从不停止。它不停地增加高度。。。这是密码 我在我的页面上添加了这个脚本,我想要iframe <script> function alertsize(pixels){ pixels+=0; document.getElementById('myiframe').style.height=pixels+"px"; } </script> <script type

你好,经过几个小时的搜索,我发现了一个适用于我的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>

函数大小(像素){
像素+=0;
document.getElementById('myiframe').style.height=pixels+“px”;
}
var myHeight=0;
setInterval(函数(){
if(myHeight!=document.body.scrollHeight){
myHeight=document.body.scrollHeight;
父级。警报大小(myHeight);
}
},500);
以下是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”
或其他,确切的值其实并不重要。

不久前也注意到了这个问题。我通过在页面加载时为Iframe设置与设备屏幕大小相关的固定高度来解决这个问题。不知道这是否最终可以修复。使用css重置并重置iframe的值。类似iframe{margin:0 padding:0 height:0 width:0}thx的快速回答Rinku/Corsair你能给我写个例子吗?因为我不知道怎么做。。。谢谢!你能解释一下你的目标是什么吗?如果你的目标是你的iframe占据100%的高度和宽度,那么css有最简单的解决方案