开发者

Facebook comments generating javascript error

I'm having a javascript error in every browsers in local AND online when using Facebook comments.

Trying to retreive 0 or multiple comments doesn't seems to change anything.

Anyone have an idea?

Error message

Message : 'this._count开发者_运维技巧.value.0' is Null or not an Object.

All.js, Line: 48, Code: 0

URI : http://connect.facebook.net/en_US/all.js#xfbml=1

Code in the page

<fb:comments-count href="<%= WebTools.Permalink %>"></fb:comments-count>
<fb:comments href="<%= WebTools.Permalink %>" num_posts="2" width="839"></fb:comments>

Thanks in advance


I've successfully diagnosed and resolved this issue.

Here was my code that was asynchronously loading the Facebook JavaScript SDK:

(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'));

Here was my code that was initializing it:

FB.init({
    appId: {APP_ID},
    status: true,
    cookie: true,
    xfbml: true,
    oauth: true
});

Note that I've actually requested XFBML parsing twice: once when loading the JavaScript SDK (#xfbml=1), and once when initializing it (xfbml: true).

This causes the error that prevents comment-count tags from rendering.

The resolution is to eliminate one of those two declarations; I would suggest deleting #xfbml=1 from the end of the JavaScript SDK URL, as requesting XFBML parsing at load time seems to be deprecated.

My loader now looks like this:

(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";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

And everything works perfectly.

Synchronous loading

If you load the JavaScript SDK synchronously, change this:

<script src="//connect.facebook.net/en_US/all.js#xfbml=1"></script>

To this:

<script src="//connect.facebook.net/en_US/all.js"></script>


I actually found out that this is an issue on Facebook’s end.
The same code work in dev and prod, but not in local or staging...

For more informations
There is a site explaining it in details:
http://www.codepreneur.com/2011/07/facebook-like-button-not-working-or-resets-itself/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜