我使用javascript在我的页面中实现了facebook分享按钮,如下所示:
<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: "{{ user_name }}'s FOF",
link: "https://www.example.com/uploader/{{current_fof}}/share_fof/",
picture: imgsArray[0].src,
caption: window.location.href,
description: 'This FOF was taken by {{ user_name }}',
message: ''
});
});
});
</script>
<div class="share"> <img src = "{{ STATIC_URL }}images/share_facebook.png" id="share_button" type='button_count'></div>
它工作得很好但是现在我想在同一页面中放置很多帖子,并为每个帖子使用不同的分享按钮(非常FB分享按钮应具有不同的链接,标题和图像)< / strong>即可。有什么想法吗?
它使用了类似按钮,使用FB API:
<div class="fb-like" data-href="https://www.example.com/uploader/{{current_fof}}/share_fof/" data-send="true" data-layout="button_count" data-width="450" data-show-faces="false" data-font="arial"></div>
但是如何用share_button做类似的事情?有什么想法吗?
干杯,
答案 0 :(得分:3)
为每个“分享”按钮添加不同的ID,并更改每个项目的其他选项(不同的链接,标题和图像)。
例如:
<script type="text/javascript">
$(document).ready(function(){
$('#share_button1').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: "{{ user_name }}'s FOF",
link: "https://mysite.com/uploader/{{current_fof}}/share_fof/",
picture: imgsArray[0].src,
caption: window.location.href,
description: 'This FOF was taken by {{ user_name }}',
message: ''
});
});
$('#share_button2').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: "{{ user_name }}'s FOF",
link: "https://mysite.com/uploader/{{current_fof}}/share_fof/",
picture: imgsArray[0].src,
caption: window.location.href,
description: 'This FOF was taken by {{ user_name }}',
message: ''
});
});
$('#share_button3').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: "{{ user_name }}'s FOF",
link: "https://mysite.com/uploader/{{current_fof}}/share_fof/",
picture: imgsArray[0].src,
caption: window.location.href,
description: 'This FOF was taken by {{ user_name }}',
message: ''
});
});
});
</script>
按钮可以是:
<div class="share"> <img src = "{{ STATIC_URL }}images/share_facebook.png" id="share_button1" type='button_count'></div>
<div class="share"> <img src = "{{ STATIC_URL }}images/share_facebook.png" id="share_button2" type='button_count'></div>
<div class="share"> <img src = "{{ STATIC_URL }}images/share_facebook.png" id="share_button3" type='button_count'></div>