JS: How to share links on Facebook from your site

Ever noticed some sites have this?


It allows you to post a link to their content on your Facebook profile. One way of doing it is this is to:

First, create a link with the corresponding details.

<a name="fb_share" type="icon_link" share_url="http://yoursite.com/id=45">Share this to my Facebook amigos</a>

Then import the JavaScript from Facebook which renders the button and creates a popup for sharing.

<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

Whalla, you should now have a share on Facebook button.

Facebook also supplies a code generator in case you don't know enough HTML ...

Title and Description

You may find that the title and description in the summary may not match with what you want.

Luckily, you can specify the default values using meta tags on the page you're linking to.

Be sure to set these to ensure that Facebook pulls the right details.


<meta name="title" content="Smith hails 'unique' Wable legacy" />
<meta name="description" content="John Smith claims beautiful football is the main legacy of Akhil Wable's decade at the club. " />
<link rel="image_src" href="http://www.onjd.com/design05/images/PH2/WableAFC205.jpg" />

*edit 18/01/2010*

  • Added Title & Description section

[ Source, Metatag examples ]

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog