Wednesday, February 20, 2013

Updating Facebook Like button with current URL

I have a comics website, Hitting Trees with Sticks that I'd like to add the Facebook liking button to.

As you can see, the homepage has thumbnails that you can click on... the thumbnail will load the full-sized comic on viewcomic.php based on that comic's ID. I thought it'd be easy enough to add the xfbml following their tutorial. I've tried adding the xfbml and the html5 versions.

Then I added the following like button code to my viewimage.php page where the unique $imgid will be:

<div class="fb-like" id="fb" data-href="http://www.hittingtreeswithsticks.com/?action=viewimage&site=<?php echo $site; ?>&id=<?php echo $imgid; ?>" data-send="false" data-layout="button_count" data-width="60" data-show-faces="true"></div> 

When I initially click on a comic to view full size, it gives me the correct like count for that $imgid and URL (should be 0): http://www.hittingtreeswithsticks.com/?action=viewimage&site=comics&id=62

enter image description here

But, for some reason, even when I go to the next comic id, and force a URL and page reload (I have to reload this way because I'm using javascript to allow users to press keys to navigate through images and need it to reload the page and ID)...

            window.history.pushState(null, null, '.?action=viewimage&site=<?php echo $site; ?>&id=<?php echo $imgid ?>);             window.location.reload(); 

It will give me the total likes for the entire site, and not that unique $imgid for that URL: http://www.hittingtreeswithsticks.com/?action=viewimage&site=comics&id=61

enter image description here

I've even tried forcing the href attribute to update with the following javascript following Elure's tutorial:

        <script type="text/javascript">         var sUrl = window.location;         document.getElementById('fb').setAttribute('href', sUrl);     </script> 

Any ideas why?

Thanks!

Source: http://facebook.stackoverflow.com/questions/14972215/updating-facebook-like-button-with-current-url

bob costas bowl projections Jovan Belcher Charlie Batch Miguel Calero Bret Bielema blake shelton

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.