I have a facebook button no SDK:
<fb:like href="<%= @canonical_url %>" send="" layout="button_count"></fb:like>
<div id="fb-root"> </div>
<script>
// facebook recommend button
window.fbAsyncInit = function() {
FB.init({appId: 'myappid', status: true, cookie: true, xfbml: true});
};
(function() {
// delay to simulate slow loading of Facebook library - remove this setTimeout!!
var t = setTimeout(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/<%= locale_og_tag %>/all.js';
document.getElementById('fb-root').appendChild(e);
}, 0);
}());
</script>
</div>
I don't reload facebook button when I change of page, then inside my javascript file I run:
if (typeof (FB) != 'undefined') {
FB.init({ status: true, cookie: true, xfbml: true });
} else {
$.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1", function () {
FB.init({ status: true, cookie: true, xfbml: true });
});
}
but I get in console:
FB.init has already been called - this could indicate a problem
How can I fix this problem?
Thank you!
Well you are calling FB.init()
twice... You might want to heed the advice of that error message :P
You only need to call it once and you couldn't call it without having the SDK loaded so, you do have to have the SDK. You call FB.init()
to set parameters such as the app_id
, whether to render xfbml
durring initialization, etc...