Facebook Like 按钮有时出现有时不出现
我的网站上的类似按钮有奇怪的问题。当我进入页面时它会正确显示,刷新后它不会出现并且我有 javascript 错误
FB.provide 不是一个函数 [中断此错误] FB.provide('Array',{indexOf:function(a...|c.hasOwnProperty(d))a(c[d],d,c);}});
js 的初始化和异步包含如下所示 这是
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'fffffffffffffffffffffffffffffff', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
喜欢和分享按钮的输入代码:
<fb:like href="<%= link -%>" layout="button_count" font="arial"></fb:like>
<a title="Share" name="fb_share" type="button_count" share_url="<%= link -%>" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
有什么想法吗?
I have strange issue with like buttons on my site. When I enter a page it shows up correctly, than after refresh it doesn't appears and I have javascript error
FB.provide is not a function [Break on this error] FB.provide('Array',{indexOf:function(a...|c.hasOwnProperty(d))a(c[d],d,c);}});
Initialization and asynchronous including of js looks like this
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'fffffffffffffffffffffffffffffff', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
And heres the input code of like and share buttons:
<fb:like href="<%= link -%>" layout="button_count" font="arial"></fb:like>
<a title="Share" name="fb_share" type="button_count" share_url="<%= link -%>" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
Any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现顺序也很重要,所以动态加载文件时,all.js应该在FB.share js之前加载
I found that order also matters, so when loading files dynamically, all.js should be loaded before FB.share js
我想我找到了解决方案。
当我按照您的方式加载 all.js 文件时,我也遇到了问题,但是当我手动下载 all.js 并将其复制到网站上的某个位置时。之后,通过脚本标签加载它就解决了这个问题。
I think I found the solution.
When I loaded the all.js file the way you did, I also had a problem, but when I downloaded all.js manually and copied it somewhere on the site. After that, loading it through the script tag made this problem went away.
将 html 放入 DOM 后,只需调用
window.fbAsyncInit();
。After you are done with placing your html in DOM, just call
window.fbAsyncInit();
.