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

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

问题描述

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

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

这里是iframe

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

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

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

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

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

#imagePathValue 成功通过,但我似乎无法关闭对话框。

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

有任何想法吗?

推荐答案

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

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

应该这样做!

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

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