Thomas
Thomas

Reputation: 5099

Change the URL in Facebook Like Code

All the content on a site I am building is loaded dynamically using ajax so the URL never changes. Now the client would like to add a facebook 'like' button. In order to do that, I am planning to use $_GET requests to ensure the proper content gets loaded when another user clicks on the liked link. However, I can't figure out how to add these urls manually to the facebook like button. The like button just grabs the current URL, which never changes.

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

The like button code:

<div class="fb-like" data-send="false" data-layout="button_count" data-width="100" data-show-faces="true" data-font="arial"></div>

Im a little new to JS but it seems like there must be a really easy way to change the url which gets sent to facebook. Any ideas?

Upvotes: 1

Views: 782

Answers (1)

Yan Berk
Yan Berk

Reputation: 14438

Add data-href to the button:

<div class="fb-like" data-href="http://www.example.com" data-send="false" data-width="450" data-show-faces="true"></div>

Upvotes: 6

Related Questions