javascript - FB Share JavaScript“未定义share_button”
问题描述
您好,我正在尝试在我的 javascript 代码中实现 facebook 的共享,但是我收到此错误,我尝试了几种建议的解决方案,但没有一个在我的实现中成功。
有人可以帮我纠正这个错误吗?
提前致谢。欢迎任何帮助。
完整代码: https ://pastebin.com/kSgFDf0L
控制台错误。
FB Share JavaScript "share_button is not defined"
$(document).ready(function() {
window.fbAsyncInit = function() {
FB.init({appId: 'xxxx', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
$(document).ready(function(){
$('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: 'This is the content of the "name" field.',
link: 'http://www.groupstudy.in/articlePost.php?id=A_111213073144',
picture: 'http://www.groupstudy.in/img/logo3.jpeg',
caption: 'Top 3 reasons why you should care about your finance',
description: "What happens when you don't take care of your finances? Just look at our country -- you spend irresponsibly, get in debt up to your eyeballs, and stress about how you're going to make ends meet. The difference is that you don't have a glut of taxpayers…",
message: ""
});
});
});
$(".result").on("click", function() {
var id = $(this).attr("data-linkId");
var url = $(this).attr("href");
if(!id) {
alert("data-linkId attribute not found");
}
increaseLinkClicks(id, url);
return false;
});
var grid = $(".imageResults");
grid.on("layoutComplete", function() {
$(".gridItem img").css("visibility", "visible");
});
grid.masonry({
itemSelector: ".gridItem",
columnWidth: 200,
gutter: 5,
isInitLayout: false
});
$("[data-fancybox]").fancybox({
caption : function( instance, item ) {
var caption = $(this).data('caption') || '';
var siteUrl = $(this).data('siteurl') || '';
if ( item.type === 'image' ) {
caption = (caption.length ? caption + '<br />' : '')
+ '<a href="' + item.src + '">View image</a><br>'
+ '<a href="' + siteUrl + '">Visit page</a><br>'
+ '<a href="' + share_button + '">Share</a>';
}
解决方案
我相信通过声明变量就可以执行函数。我只是不知道它是否会按照您的期望工作。好。我相信这行得通->
caption : function( instance, item ) {
var caption = $(this).data('caption') || '';
var siteUrl = $(this).data('siteurl') || '';
var share_button = $('#share_button') || '';
推荐阅读
- c# - 为什么我的代码会抛出 System.ArgumentException(路径中的非法字符)?
- traefik - traefik 中只能注册一个 HTTP 路由器
- java - 如何在回收器视图中访问 MainActivity 的组件以制作 onclick 监听器?
- groovy - Gremlin - 从图中获取所有边 ID 的内存/时间有效方法
- excel - 自动发送电子邮件时Excel VBA自动过滤错误
- c - 如何修改字符串并返回?
- typo3 - 如何在 Typo3 版本 10 ($GLOBALS['TYPO3_DB']->sql_query()) 中执行普通 SQL?
- python - 无法使用 Python 从 Windows 上生成的子进程中读取标准输出
- javascript - React JS material-ui itemlist对话框没有关闭
- javascript - 离线时更新缓存存储