3

我的网站上有类似按钮的奇怪问题。当我进入一个页面时它会正确显示,而不是刷新后它不会出现并且我有 javascript 错误

FB.provide is not a function
[Break on this error] 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>

有任何想法吗 ?

4

3 回答 3

6

我发现顺序也很重要,所以在动态加载文件时,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>
于 2010-10-10T15:23:57.940 回答
0

我想我找到了解决方案。

当我以您的方式加载 all.js 文件时,我也遇到了问题,但是当我手动下载 all.js 并将其复制到网站的某个位置时。之后,通过脚本标签加载它使这个问题消失了。

于 2010-10-08T13:55:41.267 回答
0

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

于 2017-10-13T05:44:39.053 回答