How to close the Facebook pop-up login window after the user Connects?
Below is my code. For some reason, after the user logs into the little pop-up window, the little window will redirect back to '/" with a lot of session JSON junk at the end of the URL.
How do I make it so that the litt开发者_开发问答le window closes, and my parent window refreshes?
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script>
<fb:login-button v="2" onlogin='window.location("/test");' size="medium">Connect</fb:login-button>
<script type="text/javascript">FB.init("XXXXX",'/xd_receiver.htm');</script>
I just solved a similar issue, that when you login with the Facebook login popup window, and it closes, the page didn't refresh.
My Facebook APP wasn't properly configured. Just go to your application settings in Facebook and specify the correct Site URL (under the Web Site section). If you are testing it locally you can put http://localhost/
Hope this helps!
Page Reloading
Try setting the reloadIfSessionStateChanged
flag for FB.init
. For example,
FB.init( "myAPIkey",
"path/to/xd_receiver.htm",
{"reloadIfSessionStateChanged": true}
);
From the Facebook API
reloadIfSessionStateChanged
bool - If the value is true, Facebook will monitor changes in session state and reload the current page if the session state changes. This option is convenient for an implementation that needs to reload the page whenever session state change in order to generate different content from server side.
For more info check out http://developers.facebook.com/docs/?u=facebook.jslib.FB.Facebook.init
Popup Not Closing
I've found that you may have issues with your popup window not closing if your path/to/xd_receiver.html
is incorrect, or if your onlogin
function for your Connect Button is undefined, so be sure to double check those.
Hope that helps!
You can use the onlogin attribute this way:
onlogin="document.location.href=document.location.href;"
This will be executed by the opener (refreshing the page).
If you remove the onlogin attribute the pop up will also close, but the page below do not refresh.
I wrote a tutorial about integrating a community with facebook connect, you can read it here.
It looks like you have a random 'h' in your code. Could this be messing with the JS functionality?
FB.init("XXXXX",'/xd_receiver.htm'h);
^
My popup wasn't closing (when posting to a feed) because I didn't have the channel.html file in the right place. After doing the post it redirects to the channel.html file in order (partly) to close the popup - so not having it in the right place meant it didn't close.
I solved it. It was to do with my settings in FAcebook's page.
精彩评论