Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 521
Ray Fall Avatar asked Dec 17 '22 04:12

Ray Fall


1 Answers

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
}
like image 51
DMCS Avatar answered Jan 24 '23 19:01

DMCS