Drupal: how to add a “share in facebook” link without IE8 crashing
I am developing a Drupal website and my client wants a “Share in facebook” button to appear in his news.
Well, first time I thought about using addthis but I did not want to depend on addthis.
Then I tried to use the facebook share tool, which they claim to be something simple to use, just these lines:
<a name="fb_share" type="button" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
But then, when using Internet Explorer 8, the page was not rendering ok, and this message was shown:
FB.loader is null or not an object.
http://static.ak.fbcdn.net/connect.php/js/FB.Share
FB.Share line:15
Code:0 Char:1
And Firebug tells me:
FB.Loader is undefined
FB.Share()FB.Share (line 15)
[Break on this error] FB.Loader.onScriptLoaded(["FB.Share","FB.SharePro"]);
The solution to this problem seems to be easy, as explained in this post, it is supposed to work fine by just adding a call to “FB.Loader” function:
But in my case it still did not work properly, so I decided to use another code to genereate a “Facebook share” button:
I edited my node-story.tpl.php, deleted the following lines:
<a name="fb_share" type="box_count" share_url="<?php echo url("node/".$node->nid,array("absolute"=>true)); ?>" href="http://www.facebook.com/sharer.php?t=<?php echo $node->title; ?>">Compartir</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Loader" type="text/javascript"></script><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>And added these ones:
<script>
function fbs_click(){
u=location.href;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
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?6:26981) no-repeat top left; }
</style>
<a rel="nofollow" href='http://www.facebook.com/share.php?u=<?php echo url("node/".$node->nid,array("absolute"=>true)); ?>' onclick="return fbs_click()" target="_blank" class="fb_share_link">Compartir</a>
<br />Easy and no annoying problems
Related posts:
Hi,
very nice post about types of contents in drupal, i have a question
What module do you recommed me for slideshow inside a node and a description, im looking for but nothing.
Thanks
Is there anymore information you can give on this subject. It answers a lot of my questions but there is still more info I need. I will drop you an email if I can find it. Never mind I will just email you using the contact form. Hopefully you can help me further.