Web Development Blog

24K Design Studio :: Blog :: Bug between AddThis and Facebook. And a Fix.
Author:
Password:
Bug between AddThis and Facebook. And a Fix.
06:18, 10 Mar, 2011
by David

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?  :)

Reply:
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2

Reply
#1
Online gambling black jack
17:08, 17 Jun, 2013
 
fivxp35l/dpn/th, <a href="http://hubertuschiro.com/">Smokeless electronic cigarette</a>, fptkSEq, [url=http://hubertuschiro.com/]Electronic Cigarette[/url], DeIhqfV, http://hubertuschiro.com/ Electronic cigarette fifty-one, uiFeWaS, <a href="http://www.nrapublications.org/">Easy no faxing payday loans</a>, CpFGiSb, [url=http://www.nrapublications.org/]Payday Loans[/url], VBPWXIR, http://www.nrapublications.org/ Us pay day loans, QJOruBS, <a href="http://www.cesconsultinggroup.ca/">Online gambling australia</a>, AYMvOMh, [url=http://www.cesconsultinggroup.ca/]Win money gambling online[/url], jfiPyoV, http://www.cesconsultinggroup.ca/ Casino casino directory gambling online, ennpWwz, <a href="http://www.altanservices.com.au/">Real pokies online</a>, tqiPcii, [url=http://www.altanservices.com.au/]Online Pokies[/url], fvBUsAr, http://www.altanservices.com.au/ Online Pokies, LTRFxaL, <a href="http://volleyballnovascotia.ca/">Casino Online</a>, VbOIQDn, [url=http://volleyballnovascotia.ca/]Poker room andnot casino online internet[/url], kVJlifS, http://volleyballnovascotia.ca/ Casino online no deposit bonus, OHOzDPF, <a href="http://miningfm.com.au/">Casino Online</a>, SSzLzEx, [url=http://miningfm.com.au/]Online casino[/url], UuYvJPL, http://miningfm.com.au/ Craps casino online, cxLgMOt.
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2

Reply
#1
qpejbsxk
05:03, 25 Nov, 2015
 
1
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2

Reply
#1
xpsolikn
05:03, 25 Nov, 2015
 
1
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2

Reply
#2
swxameoj
05:03, 25 Nov, 2015
 
1
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2

Reply
#1
dywcwwfd
05:03, 25 Nov, 2015
 
1
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2

Reply
View the latest 5 entries.