我最近添加了 facebook like 按钮,但以下代码在 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 -->
点赞按钮有效,但错误很烦人,有人知道如何解决吗?
谢谢
最佳答案
我最近在尝试注入(inject) http://connect.facebook.net/en_US/all.js 时遇到了同样的问题进入谷歌阅读器(对于这个激动人心的 Kynetx 编码竞赛:http://code.kynetx.com/2011/04/26/250-to-build-kynetx-facebook-send-within-24hrs-ends-apr-27th/)。 all.js 以“if (!window.FB) window.FB = { ...”开头并声明“提供”方法。在谷歌阅读器中,FB 对象已经存在(不知道为什么或如何创建它)所以 if 中的代码从未执行过。我使用的技巧是在包含“http://http://connect.facebook.net/en_US/all.js”之前将 FB 设置为 null。 Google Reader 没有提示。这也可能是您的情况的解决方案。 更新:您可能需要通过这种方式将 FB 设置为 null:
var head = $("head").get(0); // using jquery
var script2 = document.createElement("script");
script2.innerHTML = "window.FB = null;FB=null;";
head.appendChild(script2);
关于javascript - Facebook 点赞 : Uncaught TypeError: Object #<an Object> has no method 'provide' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3110991/