javascript - Facebook Like button sometimes appears sometimes not - Stack Overflow

I have strange issue with like buttons on my site. When I enter a page it shows up correctly, than afte

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/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=".php">Share</a><script src=".php/js/FB.Share" type="text/javascript"></script>

Any ideas ?

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/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./sharer.php">Share</a><script src="http://static.ak.fbcdn/connect.php/js/FB.Share" type="text/javascript"></script>

Any ideas ?

Share Improve this question edited Feb 20, 2014 at 18:08 Kara 6,22616 gold badges53 silver badges58 bronze badges asked Jul 22, 2010 at 13:07 Artur79Artur79 13.7k1 gold badge24 silver badges23 bronze badges 3
  • Have you tried removing /js/FB.Share script (for testing)? – serg Commented Jul 22, 2010 at 17:39
  • 1 I too have similar problem. This errors appears only in Firefox. – Goran Commented Oct 8, 2010 at 13:21
  • 2 Goran, placing the all.js on your own server is not remended, as it is a 'work-in-progress'-kinda file -- they keep changing it from time to time. – Bondt Commented Mar 7, 2011 at 15:39
Add a ment  | 

3 Answers 3

Reset to default 6

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/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/connect.php/js/FB.Share';
                s.async = true;
                document.getElementById('fb-root').appendChild(s);
              });

            </script>

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.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744094999a4557782.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信