FB is not defined

有些话、适合烂在心里 提交于 2019-12-22 08:10:44

问题


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.


回答1:


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
}


来源:https://stackoverflow.com/questions/9019207/fb-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!