从 Iframe 关闭 jQuery UI 对话框 [英] Close jQuery UI Dialog from Iframe

查看:39
本文介绍了从 Iframe 关闭 jQuery UI 对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了以下代码,用于在 jQuery 对话框中上传照片(使用 iframe).

这是 iframe

<iframe id="upload-form" frameborder="0" marginheight="0" marginwidth="0" src="Upload.aspx"></iframe>

这是父页面上负责打开对话框的 jQuery 代码.

$("#upload-image").click(function (e) {e.preventDefault();$('#upload-form').dialog({模态:真,宽度:300,title: "上传图片",自动打开:真,关闭:函数(事件,用户界面){ $(这个).对话('关闭')}});});

然后我在上传成功后注入一个脚本(在 iframe 页面上),将结果传递回父页面,但我想同时关闭对话框.

$(document).ready(function () {$(parent.document).find('#imagePathValue').val('theimagevalue');$(parent.document).find('#upload-form').dialog('close');});

#imagePathValue 成功传递,但我似乎无法关闭对话框.

有什么想法吗?

解决方案

为了使其工作,您必须从父级调用 jQuery,而不是从 iframe 中调用.为此,请使用以下...

window.parent.jQuery('#upload-form').dialog('close');

应该可以!

I've implemented the following code for uploading photos inside a jQuery dialog (using an iframe).

Here's the Iframe

<div style="display: none">
    <iframe id="upload-form" frameborder="0" marginheight="0" marginwidth="0" src="Upload.aspx"></iframe>
</div>

And here's the jQuery code on the parent page which takes care of opening the dialog.

$("#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') }
    });
});

I'm then injecting a script (on the iframe page) after the upload is successful which passes a result back to the parent page, but I want to close the dialog at the same time.

$(document).ready(function () {
    $(parent.document).find('#imagePathValue').val('theimagevalue');
    $(parent.document).find('#upload-form').dialog('close');
});

The #imagePathValue is passed successfuly, but I can't seem to be able to close the dialog.

Any ideas?

解决方案

In order to make it work, you have to call the jQuery from the parent, not from within the iframe. To do this, use the following...

window.parent.jQuery('#upload-form').dialog('close');

That should do it!

这篇关于从 Iframe 关闭 jQuery UI 对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆