Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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 Iframe大小调整问题_Javascript_Jquery_Html - Fatal编程技术网

Javascript Iframe大小调整问题

Javascript Iframe大小调整问题,javascript,jquery,html,Javascript,Jquery,Html,我正在将动态加载到IFrame中。还可以使用以下代码根据表单大小调整iframe的大小: Javascript: function iframeLoaded(i) { var iFrameID = document.getElementById(i); if (iFrameID) { iFrameID.height = ""; iFrameID.height = iFrameID.contentWindow.document.body.scroll

我正在将动态加载到IFrame中。还可以使用以下代码根据表单大小调整iframe的大小:

Javascript:

function iframeLoaded(i) {
    var iFrameID = document.getElementById(i);
    if (iFrameID) {
        iFrameID.height = "";
        iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
    }
}
HTML:


但对于大型表单,iframe没有正确调整大小。不要展示完整的形式

以下是您希望轻松完成任务的方法

所做的唯一更改是在每次加载时将高度重置为0,以使某些浏览器能够降低高度

将此添加到标签:

函数大小调整框架(obj){
obj.style.height=0;
obj.style.height=obj.contentWindow.document.body.scrollHeight+'px';
}


在iframe下面插入JavaScript

将此JavaScript放在iframe下面的某个位置。它可能在页面末尾关闭和/或从外部文件导入


函数AdjustIframeHeightOnLoad(){document.getElementById(“form iframe”).style.height=document.getElementById(“form iframe”).contentWindow.document.body.scrollHeight+“px”}
函数AdjustIframeHeight(i){document.getElementById(“form iframe”).style.height=parseInt(i)+“px”}

何时调用
iframeload
函数?似乎在完全加载之前调整了iframe的大小。我在frame的onload事件中调用了它。您可以尝试使用jQuery:
$(i).height($(i).contents().height())不工作。。即使框架没有调整大小,您能在答案中添加完整的代码吗?(涉及HTML和javascript)
<div class="row ">
    <div class="col-md-12">
        <div>
            <iframe id="CustomFormIframe" onload="iframeLoaded(this.id)" style="width:100%!important;min-height:150px; background-color:white;" frameborder="0" scrolling="no"></iframe>
        </div>
    </div>
</div>
<iframe onload='resizeIframe(this)'></iframe>