brunn
brunn

Reputation: 1383

Click facebook like button and be taken to another url

Is something like this possible?

I have a client launching an online magazine for his business. He wants to add a facebook like button (for the magazine fanpage) on his current corporate site and ask users to 'like it' in order to be taken to the magazine website. Can it be done? Are there drawbacks to this approach? For example, the same user will have to 'like it' every time they want to access the magazine site?

Thank you for any suggestion, I'm pretty new to facebook.

Upvotes: 3

Views: 1014

Answers (1)

Jont
Jont

Reputation: 972

You can redirect a user on clicking a like button using the Javascript SDK and FB.Event.Subscribe

FB.Event.subscribe('edge.create', function(response) {

    window.parent.location = 'http://www.google.com';

});

edge.create is called when ever a user likes something on the page

response is the url that has just been liked.

If there are multiple like buttons on the page you could use an if statement with the response to make sure the page only redirects for a particular like button

Here's the full javascript code and a like button

<div id="fb-root"></div>    
<script>
      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'YOUR_APP_ID', // App ID
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          oauth      : true, // enable OAuth 2.0
          xfbml      : true  // parse XFBML
        });

        FB.Event.subscribe('edge.create', function(response) {

            window.parent.location = 'http://www.google.com';

        });
      };

      // Load the SDK Asynchronously
      (function(d){
         var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/<?php if(isset($fb_user['locale'])){echo $fb_user['locale'];}else{echo'en_US';}?>/all.js";
         d.getElementsByTagName('head')[0].appendChild(js);
       }(document));
</script>

<fb:like href="http://www.google.com" send="false" width="450" show_faces="true"></fb:like>

Upvotes: 2

Related Questions