css - 为什么 chrome 每次加载 iframe 时都会将 iframe 的高度增加 10px?

标签 css google-chrome iframe resize autosize

<button class="btn btn-success" id="opener" onclick="ValidateReport('<%=generatecampaign%>','<%=loading_img_path%>','<%=IS_HTML%>','Campaign_Report');">Preview</button>

上面是我的预览按钮

以下是我的 iframe,它在 iframe 中加载一些 html 并使用将在 iframe 中加载的 html 文件中的数据调整 iframe 的大小

<div class="bordercolor" id="mydiv" style="display: none; text-align: center">

    <IFRAME SRC="" id="reportpreview"  style="text-align: center; clear:both;"
        marginheight="0" frameborder="0" onLoad="sizeFrame();"></iframe>
        <iframe id="myIFrm" src="" style="display: none;"> </iframe>
</div>

上面是我的 iframe,它加载 html 文件并根据 html 文件内容调整 iframe 内容的大小...当没有 html 文件时,只需加载一个标签名称为“No”的静态 html 文件数据可用"

我的问题是当我使用 chrome 并且当我想加载 html 文件时..它会自动增加 iframe 10pt 的高度。连续按下预览按钮。但是为什么当我尝试调整 iframe 高度时它不清除以前的高度值...

以下是我在 javascript 中调用 iframe onLoad 的 sizeFrame() 函数

function sizeFrame() {

    var F=null;
     F = document.getElementById('reportpreview');
    if(F.contentDocument) {
        F.height=0;
    F.height = F.contentDocument.documentElement.scrollHeight+10; //FF 3.0.11, Opera 9.63, and Chrome
    } else {


        F.height=0;
    F.height = F.contentWindow.document.body.scrollHeight+10; //IE6, IE7 and Chrome

    }

    }

最佳答案

使用 css 重置并重置 iframe 的值。
类似于 iframe{ margin:0 padding:0 height:0 width:0}。我以前有过噩梦般的经历,其中 web-kit 浏览器添加了几个 px 来为滚动条腾出空间。从那时起,我开始在我的元素中使用适当的 css-reset,即使它增加了开销。

关于css - 为什么 chrome 每次加载 iframe 时都会将 iframe 的高度增加 10px?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14809484/

相关文章:

jquery - 事件(选中)、悬停和非事件选项卡/div css 逻辑

javascript - 如何使用 Javascript 打断一个单词

google-chrome - 从外部进程获取当前事件的 Chrome 或 chrome 选项卡的 URL

javascript - Google Chrome native 表单错误事件

javascript - iframe 中嵌入的页面中的 YouTube 视频在 Firefox 中不起作用

javascript - Angular : src attribute bug in Iframe directive

html - 仅使用 CSS 为移动以占据空白空间的元素设置动画

css - css 选择器和 jQuery 组合的问题

javascript - 最新包含 Blink 的浏览器(如 Chrome、Opera)中的奇怪滚动行为

javascript - 纵横比为 16 的水平和垂直居中的 iframe :9 that uses as much screen estate as possible without being cropped anywhere