Ray Fall
Ray Fall

Reputation: 43

FB is not defined

I am trying to redirect to an URL if the Facebook Like button has been pressed, but it doesn't work, and results having an error in the source view saying "FB is not defined"

Here's my redirect code:

    FB.Event.subscribe('edge.create',
    function(response) {
        location.href = 'censored';
    }
);

and here's the FB 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>

<center><fb:like href="http://www.siriforall.net" send="true" width="450" show_faces="false"></fb:like></center>

Anyone help please? I am a noob sorry.

Upvotes: 4

Views: 6685

Answers (1)

DMCS
DMCS

Reputation: 31880

Ensure your FB.Event is inside of the fbAsyncInit function so you assured that the JS SDK framework has been loaded into the browser. Also be sure to call FB.init() first before calling FB.Event.

window.fbAsyncInit=function() {
   // YOUR CODE HERE THAT USES FB.anythin
}

Upvotes: 12

Related Questions