Facebook Like 按钮有时出现有时不出现

发布于 2024-09-10 19:03:01 字数 1347 浏览 4 评论 0原文

我的网站上的类似按钮有奇怪的问题。当我进入页面时它会正确显示,刷新后它不会出现并且我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初见终念 2024-09-17 19:03:01

我发现顺序也很重要,所以动态加载文件时,all.js应该在FB.share js之前加载

<script type="text/javascript">
              window.fbAsyncInit = function() {
                FB.init({appId: 'xxxxxxxxxxxxxxxxxxxxxxx', 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);
              }());

              $(document).ready(function(){
                var s = document.createElement('script');
                s.type = 'text/javascript';
                s.src = 'http://static.ak.fbcdn.net/connect.php/js/FB.Share';
                s.async = true;
                document.getElementById('fb-root').appendChild(s);
              });

            </script>

I found that order also matters, so when loading files dynamically, all.js should be loaded before FB.share js

<script type="text/javascript">
              window.fbAsyncInit = function() {
                FB.init({appId: 'xxxxxxxxxxxxxxxxxxxxxxx', 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);
              }());

              $(document).ready(function(){
                var s = document.createElement('script');
                s.type = 'text/javascript';
                s.src = 'http://static.ak.fbcdn.net/connect.php/js/FB.Share';
                s.async = true;
                document.getElementById('fb-root').appendChild(s);
              });

            </script>
情独悲 2024-09-17 19:03:01

我想我找到了解决方案。

当我按照您的方式加载 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.

无人问我粥可暖 2024-09-17 19:03:01

将 html 放入 DOM 后,只需调用 window.fbAsyncInit();

After you are done with placing your html in DOM, just call window.fbAsyncInit();.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文