Close Facebook Dialog (popup)
I am building an facebook app which runs in a tab of a site as an iframe.
for popups I use the recommended stuff from here:
when i open a popup like so:
var friend_url = "http://www.facebook.com/dialog/apprequests?app_id=**appid**&display=popup&开发者_如何学Goamp;redirect_uri=**canvasurl**&message=Mesage!"
window.open(friend_url, "Friends", "height=400,width=580,modal=yes,alwaysRaised=yes");
then a dialpg-popup opens. what I want now. if the user clicks, accept or cancel the dialog window should close. how can I do this?
thanks.
The page that you supply as the value of redirect_uri
can issue the JavaScript command self.close();
and after the user selects "accept" or "cancel", Facebook will redirect to the supplied redirect_uri
location, closing the window. Just make sure to do any processing you need to do re: error handling or processing the response, before you close the window. Once you do, it's gone!
Edited to reflect comment below:
var auth_win = window.open(friend_url, "Friends", options);
Then you'll need to detect somehow that the user's action is complete, and issue something like:
auth_win.close();
If you can't detect when the action is complete, there is some disconnect. If you mean that the redirect_uri is always your tab application, or your canvas URL, then you can add parameters to the query string, i.e. url?auth=complete
or after a hash, i.e. url#authorized
. Then once this is detected, close the window referenced by the variable.
精彩评论