The Share dialog gives people the ability to publish an individual story to their timeline, a friend's timeline, a group, or in a private message on Messenger. This does not require Facebook Login or any extended permissions, so it is the easiest way to enable sharing on the web.
If people are in a browser that is not logged in with a cookie, the drop-down list for choosing the audience for your share doesn't appear. This is also true if the app uses the feed dialog instead of the share dialog or if the app uses iframe web view.
To implement the Share Dialog in native mobile apps read our guides for iOS and Android.
The Share dialog is available in the Facebook SDK for JavaScript. You can use the following code snippet to trigger the Share dialog. You can also use a redirect to a URL. For details, see Advanced Topics.
Trigger a Share Dialog using the FB.ui function with the share
method parameter to share a link.
To share a link:
FB.ui({ method: 'share', href: 'https://developers.facebook.com/docs/', }, function(response){});
Include open graph meta tags on the page at this URL to customize the story that is shared back to Facebook.
Note that response.error_message
will appear only if someone using your app has authenciated your app with Facebook Login.
The JS SDK will provide these parameters automatically.
Parameter | Description |
---|---|
| Your app's unique identifier. Required. |
| The URL to redirect to after a person clicks a button on the dialog. Required when using URL redirection. |
| Determines how the dialog is rendered.
|
share
ParametersParameter | Description | Default |
---|---|---|
| The link attached to this post. Required when using method | Current URL |
| A hashtag specified by the developer to be added to the shared content. People will still have the opportunity to remove this hashtag in the dialog. The hashtag should include the hash symbol, e.g. |
|
| A quote to be shared along with the link, either highlighted by the user or predefined by the developer, as in a pull quote on an article. |
|
| If set to |
|
Parameter | Description |
---|---|
| Only available if the user is logged into your app using Facebook Login. |
You can also take advantage of the following advanced features.
The mobile web share dialog also has the ability to be show in an iFrame on top of your content. If a person finishes the sharing flow, the dialog will dismiss and leave them back to the original piece of content so they can easily continue consuming it.
To enable the mobile web share dialog in an iframe, set the attribute mobile_iframe
to true
:
FB.ui({ method: 'share', mobile_iframe: true, href: 'https://developers.facebook.com/docs/', }, function(response){});
To share a link:
https://www.facebook.com/dialog/share? app_id=145634995501895 &display=popup &href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F &redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fexplorer
Note: When testing this code, remove the line breaks. Otherwise you will run into an error.
Trigger a Share Dialog using the FB.ui function with the share_open_graph
method parameter to share an Open Graph story.
To share an Open Graph story with the dialog:
FB.ui({ method: 'share_open_graph', action_type: 'og.likes', action_properties: JSON.stringify({ object:'https://developers.facebook.com/docs/', }) }, function(response){});
Note that URL redirection works the same way as for standard link shares.
share_open_graph
ParametersUse the same parameters as for sharing a standard link, but add the following:
Parameter | Description |
---|---|
| A string specifying which Open Graph action type to publish, e.g., |
| A JSON object of key/value pairs specifying parameters which correspond to the |
The share_open_graph
dialog does not support mobile_iframe: true
.