如何触发fb分享与另一个按钮在我的网站上使用php


How to trigger fb share with another button on my website using php

我知道如何在我的网站上添加facebook分享按钮来分享facebook页面上的内容。然而,我想知道如何触发这个共享按钮,当我点击同一页面上的另一个按钮。下面是我希望它的功能:

  1. 我有管理后端批准用户的帖子,然后显示在前端。

  2. 一旦管理员点击批准按钮(运行jquery函数),那么这个用户的帖子也将在管理员fb的页面上共享。

这里是审批链接,用于审批admin-end中的帖子:

<td style='padding-left:5px'><a id='$rowi[postid]' class='adminapprovepost' href='#'>Approve</a></td>
下面是js代码:
$(function() {
$(".adminapprovepost").click(function(){
var id = $(this).attr("id");
var proceed = true;
    while(proceed) {
        tag = prompt("You must input at least one keyword for this post");
        if (typeof(tag) == "string") {
            tag = tag.trim()
            if (tag!="") {
                proceed = false;
            }
        }
        if (tag===null) {
            proceed = false;
        }
    }
if(tag!=null)
{
$.ajax({
type: "POST",
url: "/admin/admin-approve-post.php",
data: {id:id,tag:tag},
success: function(){
}
});
$(this).parents(".postrecord").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
这是我的facebook共享代码:
<div class="fb-share-button" data-href="https://www.mywebsite.com" data-layout="button_count"></div>

下面是fb代码的JS:

<div id="fb-root"></div>
<script>(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/sdk.js#xfbml=1&version=v2.4&appId=920558657967273"    ;
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

一旦admin点击批准按钮(运行jquery函数)

在ajax成功的时候可以触发点击:

success: function(){
   $('.fb-share-button').trigger('click');
}