It's almost 11am and I'm still awake from yesterday. I'm very likely
not communicating well :)

To close the thickbox, you need to call TB_remove(). But you can't
just call TB_remove from one of your pages that have been loaded in
the thickbox iframe, it needs to be called from the top level page
that created the thickbox. So to close the thickbox from within the
thickbox, you have to do parent.TB_remove(). Since you mentioned
wanting to do other processing when the thickbox closed, I suggested
you wrap it in another function that I arbitrarily called
thickboxDone(). This function would also be part of your main top
level page, like TB_remove is, and would allow you to close the
thickbox and do some "other stuff" then too. To call thickboxDone from
within the iframe, you have to do parent.thickboxDone(), just like you
would have to do parent.TB_remove().

So the setup might look like this:

On your main page where you launch the thickbox from, you have a function like:

function thickboxDone() {
 TB_remove();
 $.ajax(...);
}

Then from within the thickbox iframe, you would call
parent.thickboxDone(). When you should call that depends on your
setup. If you're using ajax to process your form in the thickbox, you
could call that from your ajax callback. If you're using separate
pages for your form, you could have the "success" page simply look
like:
<html><head><script>parent.thickboxDone()</script></head><body></body></html>

So when your form is successfully processed, your top level
thickboxDone() function will get called. Bear in mind that this will
only work if your form and your main page are on the exact same
domain. If only the last part of the domain is the same (like one is
www.site.com and the other is login.site.com), you can still make it
work by setting document.domain to 'site.com' on both pages.

Sorry to ramble so. Good luck with it.

--Erik


On 4/4/07, Chris W. Parker <[EMAIL PROTECTED]> wrote:

On Wednesday, April 04, 2007 10:15 AM Erik Beeson <> said:

> TB_remove() closes the thickbox, but you need to call it from the
> context of the top window, not the inner iframe window. So you
> probably want to do something like parent.TB_remove() on the last
> page. Or, if you want to remove the thickbox and update the underlying
> page, you might want to just do a full refresh with
> window.location.reload(true). If you want to close the thickbox and do
> some ajax stuff, you might want to have your last page call a function
> on your main page that will do those things:
> On the main page:
> function thickboxDone() {
>   TB_remove();
>   $.ajax(...);
> }
>
> Then call parent.thickboxDone().

I'm not sure that I'm following you completely.

Where do I put the call for thickboxDone()?

What I'm confused about is how the first page (that is loaded in the TB)
can have control even after the form has been submitted to a different
page. Do I need to add an onsubmit handler to the form that runs
thickboxDone() as a callback?

It's all dependent on what the processing page does. If there are errors
in the form it will redirect to form page to show the user errors. If
the form is clean it will do some database work and then redirect to the
parent page. In the latter case the TB should close but not the former.

(I hope I'm making sense.)


Thanks,
Chris.

Reply via email to