Close jQuery UI Dialog from Iframe

六眼飞鱼酱① 提交于 2019-11-27 04:13:59

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!

Try this:

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

In addition to that you should also do this:

window.parent.$('#upload-form').remove();

so the Iframe instance is removed after dialog close.

so Final code should be :

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

Thanks Kaushal

Definitely remember that to call those types of functions, it must refer to the function in the parent document itself. When you use the second argument of the jquery constructor, you're only specifying the target of the method, not where to execute it.

That is why $('element', window.parent.document).method(); will not work, and window.parent.jQuery('element').method(); will.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!