如何调试丢失的 Facebook Like 按钮?

发布于 2024-12-12 18:43:29 字数 2071 浏览 0 评论 0原文

我正在尝试使用 jQuery 将点赞按钮推文按钮附加到页面。推文按钮工作正常,但点赞按钮不会出现。我不知道出了什么问题,但更糟糕的是,我没有收到任何指示问题的错误或消息。

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

这是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");
    }
});

I'm trying to attach the Like Button and Tweet Button to a page using jQuery. The Tweet Button works just fine, but the Like Button won't appear. I don't know what's wrong, but worse yet, I don't get any errors or messages indicating a problem.

How can I get Facebook, Firebug, or anything to tell me what's missing, or throw appropriate errors?

Here is a demonstration on jsfiddle.

Here is the full code for those of you who don't want to go to 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");
    }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我是男神闪亮亮 2024-12-19 18:43:29

http://jsfiddle.net/ShawnsSpace/btN89/3/ 我能够得到它 生成SocMedElements() 并在页面加载后调用来工作

  1. 标头包装中添加 div 标签
  2. 通过在函数中的
  3. 。使用facebooks html5脚本。

。您必须对此进行调整才能获得所需的外观。

<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($);

http://jsfiddle.net/ShawnsSpace/btN89/3/ i was able to get it to work by

  1. adding div tag in header
  2. wrapping generateSocMedElements() in a function and calling after page load.
  3. used facebooks html5 script.

. You will have to tweek this to get the desired look.

<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($);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文