Question

i have a web site which has some Facebook like buttons like below

<div class="like-box">
  <div class="fb-like" data-href="https://www.facebook.com/samebirthday.officialpage" data-width="500" data-layout="box_count" data-action="like" data-show-faces="true" data-share="false"></div>
</div>
<div id="fb-root"></div>

<script>
  //facebook
  (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/ja_JP/all.js#xfbml=1&appId=700721206653864";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
</script>

and then, how can I add a redirect for after my Facebook page is liked? i tried this one, but it didn't work.

<script type="text/javascript">
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '700721206653864',
      status     : false, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
      xfbml      : true  // parse XFBML tags on this page?
    });

    FB.Event.subscribe('edge.create',
      function(response) {
        alert('liked!');
      }
    );

    FB.Event.subscribe('edge.remove',
      function(response) {
        alert('unliked!');
      }
    );
  };
</script>
<script src='http://connect.facebook.net/ja_JP/all.js'></script>
Was it helpful?

Solution

Use the subscribe event of as edge.create, this is the event fired when someone likes the page using a Like button. Add a redirect to it:

FB.Event.subscribe('edge.create',
      function(response) {
        window.location.href = 'http://the_URL_you_want';
      }
    );

OTHER TIPS

You need to add an EventListener on the and add it to the chain!

`

var flike = document.getElementById('-------');

flike.addEventListener('click', function(){

// here you can do the redirection

}, false); `

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top