Friday, December 14, 2007

Adding Dynamic Facebook Bookmarklets To Blogger Posts

If you are not satisfied with having just a Digg link on your blog posts, why not add a Facebook bookmarlet?

Here is the code you need (don not let the HTML entities scare you - copy this exactly):

<script>
function fbs_click()
{
u=<data:post.url/>;
t=<data:post.title/>;
window.open(&#39;http://www.facebook.com/sharer.php?u=&#39;+encodeURIComponent(u)+&#39;&amp;t=&#39;+encodeURIComponent(t),&#39;sharer&#39;,&#39;toolbar=0,status=0,width=626,height=436&#39;);
return false;
}
</script>
<style>
html .fb_share_link {
padding:2px 0 0 20px;
height:16px;
background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?43:26981) no-repeat top left;
}
</style>
<a class='fb_share_link' expr:href='"http://www.facebook.com/sharer.php?u=" + data:post.url' onclick='return fbs_click()' target='_blank'>Share on Facebook</a>
You will want to add this to or below the footer section of your template's posts includible e.g. after the third footer line.

9 comments:

Ian Thal said...

This works so nicely! Thank you!

Vikram said...

Even though it worked on mine, the icon (gif) is not in line with the others on my page.

I picked up a bigger icon (http://i261.photobucket.com/albums/ii57/ricardo_hdz/Snap3copy.gif) and tried replacing it but seems the height is restricted and the gif is displayed partly cut from the bottom.

Would appreciate if you could suggest a way out.
http://ayesaala.blogspot.com

Thanks for the code anywhich way.

sanjida shaheed said...

Good job!
But what about wordpress.com bloggers or other bloggers who are not allowed to embed anything else other than pure html codes in their blogs? In that case, only an html solution is what will do the trick and it can be found here:
How to offer a “Share on Facebook” option under (wordpress.com) blog posts

Ian Thal said...

This button works for Wordpress.

khammami said...

Thanks for the code

TVPC YOUTH MINISTRY said...

For some reason, this is not working for me... Have a simple template and do not know where to place the script...

Zen said...

Hiya,

I was wondering where the data for:
data:post.url
data:post.title

comes fromm. I am hoping to put the link in a non blog site for someone.

Many thanks for the code
Kind Regards
Zen

F. said...

I couldn't get it to work! :(
Mainly because I couldn't figure out where to put it...all the "footers" I tried just led to the entire code appearing above my navbar.

Serhad said...

worked well except I tried to use the info here

http://www.facebook.com/home.php#/share_partners.php

to change what you did to the last option because it is the same as the Share button on facebook and couln't get that to work since I have no real idea what's going on...

would you consider replicating your code of for each of the 4 official styles?

Post a Comment