How to get the parent element (not just the window) of an iframe?
<p>Similar to <a href="http://stackoverflow.com/questions/4392146/close-jquery-ui-dialog-from-iframe">this question</a>, but my setup is a little different.</p>

<p>I've written this function:</p>

<pre><code>function ShowDialog(url, width, height, id, options) {
    var self = arguments.callee;
    if(!self.dialogs) self.dialogs = {};

    var src = url + (url.indexOf('?') === -1 ? '?' : '&amp;') + '_popup=1';
    if(id) src += '&amp;_field=' + encodeURIComponent(id);

    if(url in self.dialogs === false) {
        var defaults = {
            width: width,
            height: height,
            modal: true,
            resizable: false,
            draggable: false,
            closeText: 'Close'
        };

        self.dialogs[url] = $('&lt;div/&gt;')
            .html('&lt;iframe width="100%" height="100%" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" src="'+src+'"&gt;Your browser does not support iframes.&lt;/iframe&gt;')
            .dialog(options ? $.extend(defaults, options) : defaults);
    } else {
        if(self.dialogs[url].data('reload')) {
            self.dialogs[url].data('reload', false).children('iframe').attr('src', src);
        }
        self.dialogs[url].dialog('open');
    }
    return false;
}
</code></pre>

<p>Which I use like this:</p>

<pre><code>&lt;button onclick="return ShowDialog('/companies/add', 400, 320, 'id_company');"&gt;New&lt;/button&gt;
</code></pre>

<p>When you click the button, it opens a dialog with an iframe containing a form. When you submit the form, it redirects to another page which just contains a script which is supposed to close the dialog.</p>

<p>In the other question, he has the ID of the iframe so he can find it, and then call <code>.dialog('close')</code>. I've generated my iframe on the fly, so I don't know how to access it.</p>

<p>However, I know that my iframe always sits inside a div which has the <code>.dialog</code> object... there should be a way to get the parent element of an iframe from within that iframe, no?</p>

<p>Anyone know how?</p>

<hr>

<p>Can we perhaps find it doing something like</p>

<pre><code>window.parent.jQuery(this).parent()
</code></pre>

<p>? I don't know what <code>this</code> needs to be though. Some kind of reference to itself... <code>window</code> didn't work.</p>
