繁体   English   中英

使用外部html从iFrame关闭jquery对话框

[英]Close jquery dialog from iFrame with external html

我正在尝试从内部包含外部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(copy.html)中的JS代码

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');
    }

}); 
}

我遵循了这个问题的答案: 从Iframe关闭jQuery UI对话框 ,但对我而言不起作用。

-编辑-

可以从iFrame中调用的JS函数,该函数在鬃毛html(index.html)中分配

function closeDialog(){
    console.log("Im working!!");
    document.getElementById("personal-popup").dialog("close");
    }

来自iframe的JS调用(copy.html)

$.ajax ({
  url: "php/copia.php",
  type: "post",
  data: {"params": result},
  success: function(response) {
        $.mobile.loading('hide');
        window.parent.closeDialog();
    }

}); 

从iframe内部,您可以访问window.parent

这意味着在您的主框架中您可以拥有:

window.closeDialog = function(){//Do stuff}

那么在您的iframe中,Anf有:

window.parent.closeDialog();

暂无
暂无

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

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