Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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_Iframe_Height_Width - Fatal编程技术网

Javascript 根据内容设置iFrame宽度和高度

Javascript 根据内容设置iFrame宽度和高度,javascript,jquery,iframe,height,width,Javascript,Jquery,Iframe,Height,Width,目前,我有一个jquery iframe模式对话框,可以打开一个ASPX页面。此页面包含另一个带有jQuery的iFrame。内容iframe没有设置任何高度或宽度,因此根据内部内容的大小调整大小。外部jQuery iframe模式不会根据其中的内容iframe调整大小。 以下是打开模式的代码: function openModal() { var horizontalPadding = 30; var verticalPadding = 30; var jqurl =

目前,我有一个jquery iframe模式对话框,可以打开一个ASPX页面。此页面包含另一个带有jQuery的iFrame。内容iframe没有设置任何高度或宽度,因此根据内部内容的大小调整大小。外部jQuery iframe模式不会根据其中的内容iframe调整大小。 以下是打开模式的代码:

function openModal() {

    var horizontalPadding = 30;
    var verticalPadding = 30;
    var jqurl = "ContentPage.aspx";
    var title = "Modal Title";
    jQuery('<iframe scrolling="no" id="cLaunch" class="cLaunch" src="' + jqurl + '" frameborder="0"/>').dialog({
        title: title,
        modal: true,
        resizable: true,
        position: ['center', 50],

        fluid:true,
        overlay: {
            opacity: 0.5,
            background: "grey"
        }

    });
}

setInterval(function () {
    document.getElementById("cLaunch").style.width = document.getElementById("cLaunch").contentWindow.document.documentElement.scrollWidth + 30 +  'px';
    document.getElementById("cLaunch").style.height = document.getElementById("cLaunch").contentWindow.document.body.scrollHeight + 'px';


}, 1000)
函数openModal(){
var水平填充=30;
垂直填充变量=30;
var jqurl=“ContentPage.aspx”;
var title=“模态标题”;
jQuery(“”).dialog({
标题:标题,,
莫代尔:是的,
可调整大小:正确,
位置:[‘中间’,50],
流体:是的,
覆盖:{
不透明度:0.5,
背景:“灰色”
}
});
}
setInterval(函数(){
document.getElementById(“cLaunch”).style.width=document.getElementById(“cLaunch”).contentWindow.document.documentElement.scrollWidth+30+'px';
document.getElementById(“cLaunch”).style.height=document.getElementById(“cLaunch”).contentWindow.document.body.scrollHeight+'px';
}, 1000)
ConentPage.aspx:

<iframe name="contentloader"  id="contentloader"  frameborder="0" scrolling="no"></iframe>


如果您有任何帮助,我们将不胜感激。

根据iframe内部加载的内容,尝试设置iframe的宽度和高度

$("#cLaunch").load(function() {
    $(this).height( $(this).contents().find("body").height());
    $(this).width( $(this).contents().find("body").width());
});