如何调试丢失的 Facebook Like 按钮?
我正在尝试使用 jQuery 将点赞按钮和推文按钮附加到页面。推文按钮工作正常,但点赞按钮不会出现。我不知道出了什么问题,但更糟糕的是,我没有收到任何指示问题的错误或消息。
我怎样才能让 Facebook、Firebug 或其他任何东西告诉我缺少什么,或者抛出适当的错误?
对于那些不想去 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://jsfiddle.net/ShawnsSpace/btN89/3/ 我能够得到它 生成SocMedElements() 并在页面加载后调用来工作
。您必须对此进行调整才能获得所需的外观。
http://jsfiddle.net/ShawnsSpace/btN89/3/ i was able to get it to work by
. You will have to tweek this to get the desired look.