views:

18

answers:

1

Here is how I initialize the dialog:

$('a.dialog').click(function(e) {
    e.preventDefault();
    var $this = $(this);
    $('<iframe id="externalSite" class="externalSite" src="/controller/action" frameBorder="0"></iframe>').dialog({
        modal: true,
        resizable: false,
        title: 'Title',
        zIndex: 1,
        show: 'fast',
        hide: 'slow',
        width: 600,
        height: 400,
        position: 'middle'
    }).width(600);
});

How can I close it from inside the iframe?

For example, I'd like to have a link inside the iframe that will close the dialog.

+1  A: 

You can use window.parent or window.top to reference parent window. Starting from there, you should be able to find your dialog with jquery and close it. Something like

$(window.top.document).find('#externalSite').dialog('close');

https://developer.mozilla.org/en/DOM/window.parent

Nikita Rybak
Or `window.top.$.find('#externalSite').dialog('close');` to use the jQuery object on the parent window directly, in case the page in the frame doesn't need/want jQuery itself.
Pointy
That doesn't work. But this does: $(window.top.document).find('.ui-widget-overlay, .ui-dialog').remove();
Richard Knop
@Richard I'm not familiar with jui api, looks like it's called 'destroy': http://jqueryui.com/demos/dialog/#method-destroy
Nikita Rybak
@Richard I assumed that you know how to do it without iframes already.
Nikita Rybak
@Nikita There is method close as well. It should work.
Richard Knop
@Richard Maybe it doesn't find iframe because you didn't insert it in the document? Try `alert($(window.top.document).find('#externalSite').length)`.
Nikita Rybak