Search code examples
phpfacebookhttp-redirectmodx

Facebook like button redirect?


Is it possible to add a like button feature to your Facebook page which re-directs to another page and offers the user a free ebook?

I'm creating a website within MODx which runs via PHP.


Solution

  • For only like button:

    <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>
    
    
    <div id="fblike">
      <div class="fb-like" data-href="site name" data-send="false" data-layout="button_count" data-width="100" data-show-faces="false"></div>
    </div>
    

    Redirect after clicking Like button:

    This can be handled with the Facebook javascript event, edge.create:

    FB.Event.subscribe('edge.create',
        function(response) {
            location.href = 'http://yourdomain.com/post/id';
        }
    );
    

    may this help you.