0

目前我有一个打开 ASPX 页面的 jquery iframe 模式对话框。此页面包含另一个带有 jQ​​uery 的 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)

内容页面.aspx:

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

任何帮助,将不胜感激。

4

1 回答 1

0

试试这个来设置 iframe 的宽度和高度,基于 iframe 内加载的内容

$("#cLaunch").load(function() {
    $(this).height( $(this).contents().find("body").height());
    $(this).width( $(this).contents().find("body").width());
});
于 2013-12-31T06:18:47.380 回答