i have a page where i will create a iframe dynamically and append that to a div. That div will be attached to a jquery dialog.
我有一个页面,我将动态创建一个iframe并将其附加到div。该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. can anyone suggest a workaround for this?
在jquery对话框中打开iframe时,不会写入iframe的内容。任何人都可以建议一个解决方法吗?
Update:
更新:
function test() {
var iFrame = $('<iframe id="thepage" width="500" height="500" src="http://*.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. How to load a function from jquery dialog?
我试图在jquery对话框加载后动态调用一个函数,但它显示一些错误。如何从jquery对话框加载函数?
1 个解决方案
#1
0
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.
您可能还需要为其添加一些填充,以便文本不会卡在边框上。
#1
0
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.
您可能还需要为其添加一些填充,以便文本不会卡在边框上。