Joe Betz
Joe Betz

Reputation: 41

Facebook share dialog does not close after posting or cancelling

Using v2.0 of the Facebook API, the share dialog popup doesn't close after the "Cancel" or "Post to Facebook" button has been selected. Previously, a 'redirect_uri' param was passed to the Feed endpoint, and this could be used to close the window. When trying to pass this param to the Share endpoint, however, I get the message: 'When using FB.ui, you should not specify a redirect_uri.'

Is there any way to force the popup window to close? And if not, might there be a problem with the API request? The link DOES get shared when "Post to Facebook" is selected, so I don't think it's an issue with login or permissions.

Here is what the API call looks like:

FB.ui({
    method: 'share',
    href: location.href,
)}, function(response){});

Upvotes: 4

Views: 1083

Answers (1)

Liam Butler
Liam Butler

Reputation: 43

Try adding a preventDefault. I had the FB.ui action being triggered when an anchor tag was clicked. When I clicked the link, the page refreshed. Then when I'd click 'Post to Facebook' in the popup, I presume that the callback had nowhere to go.

What worked for me:

handleFbShare = (e) => {
  e.preventDefault();
  FB.ui({
    method: 'share',
    display: 'popup',
    href: 'https://your-url/',
  }, function(response){});
}

(...)

<a href="" className='button__facebook' onClick={this.handleFbShare}>Share on Facebook</a>

Hope that helps!

Upvotes: 1

Related Questions