gpt4 book ai didi

javascript - FB 分享 JavaScript "share_button is not defined"

转载 作者:行者123 更新时间:2023-12-04 03:33:45 25 4
gpt4 key购买 nike

您好,我正在尝试在我的 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') || '';

关于javascript - FB 分享 JavaScript "share_button is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67357315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com