根据内容更改iframe高度 [英] change iframe height according to content

查看:91
本文介绍了根据内容更改iframe高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iframe代码:

  <iframe scrolling="no" style="height: 956px; width: 100%" frameborder="0" id="ampcontentiframe"></iframe>

我正在尝试调整内容load.i上的iframe高度来尝试其他解决方案:

i am trying to resize iframe height on content load.i tried other solutions from:

Link1

Link2

Link3

但是他们都没有解决我的问题。我尝试在窗口加载和iframe加载时调用resize函数。但是它设置的每个高度都是时间不同(有时是实际内容高度,有时是iframe的原始高度)。

But none of them solved my problem.i tried calling resize function on window load as well as iframe load.but the height it sets every time is different(sometimes actual content height and sometimes original height of iframe).

任何帮助人员..... ??

Any help guys.....??

FYI:我也试过从iframe中删除滚动attr。但是它不起作用

推荐答案

哟你可以尝试使用以下脚本。

You can try with the following script.

<script type="text/javascript">
  function iframeLoaded() {
    var iFrameID = document.getElementById('your_frame_id');
    if(iFrameID) {            
        iFrameID.height = "";
        iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
   }   
}
</script> 

并向你的iframe添加onload函数,如

and add onload function to your iframe like

<iframe onload="iframeLoaded()">

这篇关于根据内容更改iframe高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆