【发布时间】:2014-07-11 06:12:06
【问题描述】:
我正在尝试从内部带有外部 html 的 iframe 关闭 jQuery ui 对话框。
我的代码如下所示:
我的主 html 中的 JS 代码用于在我单击按钮时创建对话框:
function createDialog() {
return $("<div id='personal-popup' class='dialog' title='Copia de archivos'></div>")
.html('<iframe style="border: 0px; " src="copy.html" width="100%" height="100%"></iframe>')
.dialog({
resizable: true,
height: 447.59999990463257,
width: 993.5999999046326,
modal: true
});
}
其他html里面的JS代码(copy.html)
function copiarArchivos() {
$.mobile.loading('show',{
text: "Copiando",
textVisible: true,
theme: "a",
html: ""
});
var result = [];
var allOptions = $("#select-custom-19");
$("#select-custom-19 option:selected").each(function () {
var $this = $(this);
var selText = $this.text();
$this.prop("selected", false);
result.push(selText);
});
allOptions.selectmenu('refresh', true);
$.ajax ({
url: "php/copia.php",
type: "post",
data: {"params": result},
success: function(response) {
$.mobile.loading('hide');
//I want to close the dialog here when the ajax function success
$(window.parent.document).find("#personal-popup").dialog('close');
}
});
}
我已经按照这个问题的答案:Close jQuery UI Dialog from Iframe,但它对我不起作用。
--- 编辑 ---
将从iFrame中调用的JS函数,分配在mane html (index.html)中
function closeDialog(){
console.log("Im working!!");
document.getElementById("personal-popup").dialog("close");
}
来自 iframe (copy.html) 的 JS 调用
$.ajax ({
url: "php/copia.php",
type: "post",
data: {"params": result},
success: function(response) {
$.mobile.loading('hide');
window.parent.closeDialog();
}
});
【问题讨论】:
标签: javascript jquery html jquery-ui iframe