Facebook Like按钮有时会出现 [英] Facebook Like button sometimes appears sometimes not

查看:108
本文介绍了Facebook Like按钮有时会出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);}});


包含js的初始化和异步看起来像这样

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>

任何想法?

推荐答案

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

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>

这篇关于Facebook Like按钮有时会出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆