views:

21

answers:

1

So, in facebook, I cannot call myFrame.window to get the iframe parent window. How can I do it?

What I'm trying archieve is: I have a popup (div) that will load a iframe.
And then in the iframe will have a button. Once people click the button inside the iframe, I want to close the popup(div).
Normally, I need to get the parent window. Then I can destroy the popup div. But in facebook, how can I do it? any alternative way to do that?

I don't want to refresh the page. :)

A: 

If you can't access the parent from the iframe, you could try sending a function reference from the parent to the iframe.

In your parent:

iframe.contentWindow.closeFn = function() { /* destroy popup */ }

Then, in your iframe, call window.closeFn() when you want to destroy the popup.

The contentWindow may have some cross-browser issues, you can read further here

I have not tried this in Facebook myself - no guarantees it will work there, but might be worth trying.

Lauri Lehtinen
Sorry. thanks but it is not helpful. Facebook disallows direct access to some functions / variables. e.g. the window object. If not facebook, I know how to make it work. :) thanks.
seatoskyhk
I don't think Facebook can do anything about you referring to your iframe's window object from within your iframe though? If they disallow access to iframe.contentWindow, then this isn't useful either.
Lauri Lehtinen