从Iframe关闭jqueryui对话框
我已经实现了以下代码,用于在jQuery对话框中上传照片(使用iframe) 这是Iframe从Iframe关闭jqueryui对话框,jquery,jquery-ui,iframe,jquery-ui-dialog,Jquery,Jquery Ui,Iframe,Jquery Ui Dialog,我已经实现了以下代码,用于在jQuery对话框中上传照片(使用iframe) 这是Iframe <div style="display: none"> <iframe id="upload-form" frameborder="0" marginheight="0" marginwidth="0" src="Upload.aspx"></iframe> </div> 上传成功后,我将注入一个脚本(在iframe页面上),该脚本将结果传递回
<div style="display: none">
<iframe id="upload-form" frameborder="0" marginheight="0" marginwidth="0" src="Upload.aspx"></iframe>
</div>
上传成功后,我将注入一个脚本(在iframe页面上),该脚本将结果传递回父页面,但我希望同时关闭该对话框
$(document).ready(function () {
$(parent.document).find('#imagePathValue').val('theimagevalue');
$(parent.document).find('#upload-form').dialog('close');
});
#imagePathValue
已成功传递,但我似乎无法关闭该对话框
$("#upload-image").click(function (e) {
e.preventDefault();
$('#upload-form').dialog({
modal: true,
width: 300,
title: "Upload Image",
autoOpen: true,
close: function(event, ui) { $(this).dialog('close') }
});
});
有什么想法吗?试试这个:
$(document).ready(function () {
$(parent.document).find('#imagePathValue').val('theimagevalue');
window.parent.$('#upload-form').dialog('close');
});
为了使其工作,必须从父级而不是从iframe中调用jQuery。要执行此操作,请使用以下命令
window.parent.jQuery('#upload-form').dialog('close');
那就够了 除此之外,您还应该这样做:
window.parent.$('#upload-form').remove();
因此,Iframe实例将在对话框关闭后删除
因此,最终代码应该是:
$(document).ready(function () {
$(parent.document).find('#imagePathValue').val('theimagevalue');
window.parent.$('#upload-form').dialog('close');
window.parent.$('#upload-form').remove();
});
谢谢
Kaushal一定要记住,要调用这些类型的函数,它必须引用父文档本身中的函数。当您使用jquery构造函数的第二个参数时,您只是指定方法的目标,而不是在何处执行它
这就是为什么
$('element',window.parent.document).method()代码>将不起作用,window.parent.jQuery('element').method()代码>威尔。两个答案都是一样的,所以是的。谢谢。如果没有remove(),打开、关闭然后重新打开对话框可以工作,但是第二次关闭尝试失败对话框(“销毁”)可能应该改为使用;对话框创建的资源不是对话框本身的子DOM元素中引用的资源。