简体   繁体   English

未在“ jQuery查询”对话框中加载iframe内容

[英]Iframe content not loaded in JQuery Dialog

i have a page where i will create a iframe dynamically and append that to a div. 我有一个页面,我将在其中动态创建iframe并将其附加到div。 That div will be attached to a jquery dialog. 该div将附加到jquery对话框。

<div id="diviframe"></div>
<script>
var iFrame = $('<iframe id="thepage" width="450" height="400"></iframe>').appendTo("#diviframe");
    var iFrameDoc = iFrame[0].contentDocument || iFrame[0].contentWindow.document;
    iFrameDoc.write('<p>Some useful html</p>');
    iFrameDoc.write('<p>Some useful stuff</p>');   
    iFrameDoc.close();


    $("#diviframe").dialog({

        autoOpen: false,
        modal: true,
        height: 500,
        width:500,
        open: function(ev, ui) {

    }

    });

$("#diviframe").dialog('open');

The contents of iframe is not written when its opened in jquery dialog. 在jQuery对话框中打开iframe时,不会写入其内容。 can anyone suggest a workaround for this? 有人可以为此建议解决方法吗?

Update: 更新:

 function test() {
        var iFrame = $('<iframe id="thepage" width="500" height="500" src="http://stackoverflow.com"></iframe>').appendTo("#diviframe");
        var parent = "divparent";
        var iFrameDoc = iFrame[0].contentDocument || iFrame[0].contentWindow.document;
        iFrameDoc.write('<p>Some useful html</p>');
        iFrameDoc.write('<p>Some useful stuff</p>');
        iFrameDoc.close();      
        return iFrame;
    }






    var $dialog; //Must be at the global scope
    function dialog() {      
        alert(1);
        $.get(test, {}, function(html) {
            $dialog.html(html);
            $dialog.dialog("open");
        });
    }

    $(function() {
        //Initialize (without showing it)
        var $dialog = $('<div id="dialog" title=""></div>').dialog({
            autoOpen: false,
            modal: true
        });
    });
    dialog();

I tried to call a function dynamically after the jquery dialog loads but its showing some errors. 我试图在jquery对话框加载后动态调用一个函数,但是它显示了一些错误。 How to load a function from jquery dialog? 如何从jQuery对话框加载函数?

I don't think you need to use an iframe for what you're doing, unless you've stripped out some vital detail before posting your question. 我认为您无需将iframe用于正在执行的操作,除非您在发布问题之前已经剔除了一些重要的细节。

You can append your content directly to #diviframe, and it'll display just fine. 您可以将内容直接附加到#diviframe,它会很好地显示。

$("#diviframe").append("<p>Some useful html</p>");
$("#diviframe").append("<p>Some useful stuff</p>");

I wonder - are you trying to make a scrollable panel inside the dialog? 我想知道-您是否正在尝试在对话框中创建可滚动面板? If so, you can set the CSS of a div to achieve what you need: 如果是这样,您可以设置div的CSS来实现所需的功能:

.myScrollableBox {
    width: 450px;
    height: 400px;
    overflow: auto;
    border: 1px solid #000;
}

You might also want to add some padding to that, so that the text isn't jammed hard against the borders. 您可能还想在其中添加一些填充,以使文本不会紧贴边框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM