如何调试丢失的Facebook Like Button?

时间:2011-10-28 15:31:11

标签: javascript jquery dom facebook-like

我正在尝试使用jQuery将 Like Button Tweet Button 附加到页面。 Tweet按钮工作正常,但不会出现Like按钮。我不知道什么是错的,但更糟糕的是,我没有收到任何错误或消息表明存在问题。

如何让Facebook,Firebug或其他任何东西告诉我缺少什么,或者抛出适当的错误?

这是demonstration on jsfiddle

以下是那些不想去jsfiddle的人的完整代码:

/**
 * Generate the container elements for social media stuff.
 */
$(function generateSocMedElements($) {
    var id = "socmed",
        $container,
        $fb_root,
        $fb_like,
        $tweet_button;
    if ($("#" + id).length <= 0) {
        $container = $(document.createElement("aside")).
            addClass("socmed").
            attr("id", id);
        $fb_root = $(document.createElement("div")).attr("id", "fb-root");
        $fb_like = $(document.createElement("div")).
            addClass("fb-like").
            attr("data-href", "example.org").
            attr("data-send", "false").
            attr("data-layout", "button_count").
            attr("data-width", 82).attr("data-show-faces", "false");
        $tweet_button = $(document.createElement("a")).
            addClass("twitter-share-button").
            attr("href", "//twitter.com/share").
            attr("data-count", "none").
            text("Tweet");
        $container.
            appendTo($("header").first()).
            append($fb_root).
            append($fb_like).
            append($tweet_button);
    }
});

/**
 * Load the script for the Facebook API.
 */
$(function loadFacebook($) {
    var id = "facebook-jssdk";
    if ($("#" + id).length <= 0) {
        $(document.createElement("script")).
            attr("id", id).
            attr("src", "//connect.facebook.net/en_US/all.js").
            appendTo("head");
    }
});

/**
 * Load the script for the Twitter API.
 */
$(function loadTwitter($) {
    var id = 'twitterSdk';
    if ($("#" + id).length <= 0) {
        $(document.createElement("script")).
            attr("id", id).
            attr("src", "//platform.twitter.com/widgets.js").
            appendTo("head");
    }
});

1 个答案:

答案 0 :(得分:4)

http://jsfiddle.net/ShawnsSpace/btN89/3/我能够通过

让它工作
  1. 在标题
  2. 中添加div标记
  3. 在函数中包装generateSocMedElements()并在页面加载后调用。
  4. 使用facebooks html5脚本。
  5. 。你必须调整它以获得所需的外观。

    <header><h1>OH HAI I HAZ A HEADER</h1>
    <div id="fb-root"></div>
    </header>
    

    /**
     * Load the script for the Facebook API.
     */
    
    (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {return;}
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    
    
    /**
     * Load the script for the Twitter API.
     */
    $(function loadTwitter($) {
        var id = 'twitterSdk';
        if ($("#" + id).length <= 0) {
            $(document.createElement("script")).
                attr("id", id).
                attr("src", "//platform.twitter.com/widgets.js").
                appendTo("head");
        }
    });
    function loadthis($){
    $(function generateSocMedElements($) {
        var id = "socmed",
            $container,
            $fb_root,
            $fb_like,
            $tweet_button;
        if ($("#" + id).length <= 0) {
            $container = $(document.createElement("aside")).
                addClass("socmed").
                attr("id", id);
            $fb_root = $(document.createElement("div")).attr("id", "fb-root");
            $fb_like = $(document.createElement("div")).
                addClass("fb-like").
                attr("data-href", "example.org").
                attr("data-send", "false").
                attr("data-layout", "button_count").
                attr("data-width", 82).attr("data-show-faces", "false");
            $tweet_button = $(document.createElement("a")).
                addClass("twitter-share-button").
                attr("href", "//twitter.com/share").
                attr("data-count", "none").
                text("Tweet");
            $container.
                appendTo($("header").first()).
                append($fb_root).
                append($fb_like).
                append($tweet_button);
        }
    });
    }
    loadthis($);