Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook like : Uncaught TypeError: Object #<an Object> has no method 'provide'

I have recently added the facebook like button, but the following code returns an error in chrome: Uncaught TypeError: Object # has no method 'provide'

<!-- Facebook -->
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: '121814204514513', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>
<!-- Facebook -->

The like button works but the error is anoying, does anyone know how to solve that?

Thanks

like image 715
Roch Avatar asked Dec 28 '22 12:12

Roch


1 Answers

I recently got the same problem when I tried to inject http://connect.facebook.net/en_US/all.js into Google Reader ( for this exciting Kynetx coding contest : http://code.kynetx.com/2011/04/26/250-to-build-kynetx-facebook-send-within-24hrs-ends-apr-27th/ ) . all.js starts with "if (!window.FB) window.FB = { ..." and declares the 'provide' method . In google reader the FB object was already present (dont know why or how it was created) so the code inside the if never got executed. The trick I used was to set FB to null before including "http://http://connect.facebook.net/en_US/all.js" . Google Reader didn't complain. It might be a solution in your situation too. Update: you may need to set FB to null this way:

var head = $("head").get(0);  // using jquery
var script2 = document.createElement("script");
script2.innerHTML = "window.FB = null;FB=null;";
head.appendChild(script2);
like image 148
Loic Devaux Avatar answered Dec 31 '22 02:12

Loic Devaux