2

The initialization code:

            FB.init({
                appId: '123456789012345', 
                channelUrl: 'http://localhost/Some/Url/FacebookChannel',
                status: true, 
                cookie: true, 
                oauth: true, 
                xfbml: true  
            });

The following code is called with an onclick:

    FB.ui({
            method: 'feed',
            name: settings.facebookShareName,
            link: settings.facebookLinkUrl,
            caption: settings.facebookShareCaption,
            description: settings.facebookShareDescription,
            message: message,
            display: 'popup'
    });

This code works fine in FF and Chrome, and mostly works in IE8. The popup is shown and the user can post to their wall, but after submitting, the window doesn't close. It turns white with no further interaction, but must manually be closed by the user.

Why doesn't the window auto-close in IE, and/or are there any workarounds to force the popup to close?

Edit: This issue may be related to this outstanding bug.

6 Answers 6

3

I have the same problem and have never been able to get a response from Facebook for the callback function. I don't see anything in console.log or any alerts I insert in the function.

My solution was to put a URL in FB.ui's redirect_uri that goes to an HTML page with self.close (or window.close). The FB.ui popup redirects there after the user's input and immediately closes. Remember to change your FB app's Site URL setting so it matches the domain the file resides on.

Here's my code, tied to my form's submit action. The function(response) callback is still there but not used. If anyone sees a syntax error please comment on it.

    FB.ui ({
        method: 'feed',
        name: '',
        link: '',
        picture: '',
        caption: '',
        description: '',
        actions: {name:'',link:''},
        redirect_uri: 'http://.../self.close.html'
        },
        function(response) {
            console.log(response);
            if (response && response.post_id) {
                alert('yes');
                self.close();
            } else {
                alert('else yes');
            }
        });

The line of code in self.close.html:

<script type="text/javascript">self.close();</script>
1
  • This is the solution I ended up settling on as well.
    – Ryre
    Jan 26, 2012 at 21:00
3

A bit old thread, but this might help someone... The popup will self close if you neglect to put in the "redirect_uri" parameter. (plus, the response callback will now work too)

1
  • 5
    Doesn't seem to work anymore. If you don't supply the redirect_uri the share dialog will not be rendered. May 4, 2014 at 10:54
3

add return false; to your method call.

onsubmit="someMethod(); return false;"
2

Not an easy one... but it could work:

First, to force closing the dialog you must pay attention to the response: See the entire documentation and example here: https://developers.facebook.com/docs/reference/javascript/FB.ui/

Once you have the response you should close the dialog: See: http://facebook.stackoverflow.com/questions/4646441/how-to-close-a-facebook-sdk-dialog-opened-with-fb-ui

Hope that helps! :)

2

The pop up will close if you do not give the redirect_uri as mentioned above - as well as if you do not give display (that is, do not give display: 'popup' or display: 'iframe').

3
  • 3
    Doesn't seem to work anymore. If you don't supply the redirect_uri the share dialog will not be rendered. May 4, 2014 at 10:54
  • As of the date of this comment, and using v3.2, the window closed when I removed the redirect_uri parameter. I'm curious to know others' experiences with this. Apr 8, 2019 at 20:42
  • Also, our old code was using the accepted answer's recommendation of redirecting to a page that has one line of code: window.close(), which worked fine as well. Apr 8, 2019 at 20:45
0

Make sure 'http://localhost/Some/Url/FacebookChannel' hosted in the same domain with your app callback url.

1
  • There is no callback url; you mean canvas url? Either way, everything is set to localhost port 80.
    – Ryre
    Dec 21, 2011 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.