【问题标题】:Facebook FB sharer with jQuery- "FB is not defined" error带有 jQ​​uery 的 Facebook FB 共享器-“FB 未定义”错误
【发布时间】:2014-05-01 09:40:55
【问题描述】:

我正在实施 Facebook 分享。但是我收到错误Uncaught ReferenceError: FB is not defined。但是,如果我将代码放在 getScript 函数中(在下面的代码中),那么它可以工作,但仅在页面加载时。 看了很多this之类的答案,还是没找到解决办法。

    <div id="fb-root"></div>
    <script>
    jQuery(document).ready(function() {
      jQuery.ajaxSetup({ cache: true });
      jQuery.getScript('//connect.facebook.net/en_UK/all.js', function(){
            window.FB.init({
              appId: 'XXX',
            });     
            jQuery('#loginbutton,#feedbutton').removeAttr('disabled');
        });
        FB.ui(
          {
            method: 'feed',
            name: 'Facebook Dialogs',
            link: 'http://XXX.website',
            picture: 'http://XXX.website/logoroundTR.gif',
            caption: 'MyCaption',
            description: 'MyDescription'
          },
          function(response) {
            if (response) {
              alert('Post was published.');
            } else {
              alert('Post was not published.');
            }
          }
        );
    });
    </script>
<button><fb:like href="http://XXX.website/" layout="button_count" action="like" show_faces="true" share="true"></fb:like></button>

ps:第二个问题:如何将按钮链接到 FB.ui 函数。有什么简单的方法吗?

【问题讨论】:

    标签: facebook-javascript-sdk


    【解决方案1】:

    好的,找到了一个可行的解决方案。轻微破解。

    删除FB.ui 并将其放在按钮onclick 中,效果很好。

    因此,对于 facebook javascript sdk 的自定义标题、标题、图像和描述,可以执行以下操作:

    <div id="fb-root"></div>
    <script>
    jQuery(document).ready(function() {
      jQuery.ajaxSetup({ cache: true });
      jQuery.getScript('//connect.facebook.net/en_UK/all.js', function(){
            window.FB.init({
              appId: 'appID',
            });     
            jQuery('#loginbutton,#feedbutton').removeAttr('disabled');
        });
    });
    </script>
    <button onclick="javascript:FB.ui({method: 'feed',name: 'Facebook Dialogs',link: 'http://xxxY.com',picture: 'http://xxxy.com/wp-content/img/logoroundTR.gif',caption: 'SandeepCaption',description: 'SandeepDescription'});"> Click Here </button>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多