Using AddThis to make things sharable will be easy. However, when it is with Facebook, there is a bug. The reason might be from upgrading of Facebook. Anyway, this bug escape the web address twice and will make the shared hyperlink not accessible. (When this article is written, the bug still exists)

One simple idea is fix this. Repair the wrong sharing link with a correct one.

After some searching, I found a correct link which is relative to s=100. For our 24k designs website, it is:

"http://www.facebook.com/sharer.php?s=100&p[title]="+encodeURIComponent(document.title)+"&p[url]="+encodeURIComponent(link)+"&p[images][0]="+encodeURIComponent("http://www.24k.com.sg/images/logo.jpg")

where link is the location of the shared page.

The action is easy: when the page is loading, monitor the icon of facebook share. Once it is configurated by AddThis, change it to the correct link.

 

And here is the PHP code used by our 24k designs website:

<?php
function optShareSharethis() {
 
global $web_addr;
?>
   
<div style="margin:0px;padding:0px;border:none;" id="divSharethis">
   
<script type="text/javascript">
    $
(function() {
     $
('#divSharethis').html("<?php
     ob_start
();
     
?>
     
<!-- ")}); </script> -->
     
<!-- AddThis Button BEGIN -->
     <div id="divSharethisConfig" class="addthis_toolbox addthis_default_style"
      addthis:url="
http://www.<?php echo$web_addr.$_SERVER['REQUEST_URI']?>"
      addthis:title="One of the Best Website Design &amp; SEO Companies in Singapore"
      addthis:description="24K Design Studio is one of the most innovative and fast growing Web Design, Email Marketing, SEO Companies and Digital Marketing Agencies in Singapore.">
     
<a href="http://www.addthis.com/bookmark.php?v=250&pubid=ra-4d7764983118dc41" class="addthis_button_compact">Share</a>
     
<span class="addthis_separator">|</span>
     
<a class="addthis_button_facebook"></a>
     
<a class="addthis_button_twitter"></a>
     
<a class="addthis_button_email"></a>
     
<a class="addthis_button_print"></a>
     
</div>
     
<script type="text/javascript">
     $
('#divSharethisConfig').attr('addthis:title', document.title);
     $
(function() {
     
var shareThisFB = $('.addthis_button_facebook');
     
function shareThisFBFixAction() {
       
var link = "http://www.<?php echo$web_addr.$_SERVER['REQUEST_URI']?>";
       shareThisFB
.attr('href', "http://www.facebook.com/sharer.php?s=100&p[title]="+encodeURIComponent(document.title)+"&p[url]="+encodeURIComponent(link)+"&p[images][0]="+encodeURIComponent("http://www.24k.com.sg/images/logo.jpg"));
     
}
     
function shareThisFBFixTrigger() {
       
var hrefType = null;
       
try {
        hrefType
= typeof(shareThisFB.attr('href'));
       
} catch (e) {
       
}
       
if (hrefType == "undefined") {
        setTimeout
(shareThisFBFixTrigger, 100);
       
} else {
        shareThisFBFixAction
();
       
}
     
}
      shareThisFBFixTrigger
();
     
});
     
</script>
     
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
     
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4d7764983118dc41"></script>
     
<!-- AddThis Button END -->
     
<?php
     $buffer
= ob_get_contents();
     ob_end_clean
();
     echo jsDoubleStringEscape
($buffer);
     
?>");
    });
   
</script>
   
</div>
<?php
}
?>

For the above code
  $web_addr is our web address 24k.com.sg
  Delay loading is used as the loading of AddThis will delay the loading of remaining HTML elements.
  jquery library is used.

Hope one day this article will be useless and the bug be fixed by AddThis. Will you share this article?  :)