我使用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非常分享按钮应具有不同的链接,标题和图像)。 有任何想法吗?
它曾与喜欢按钮,使用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类似的事情? 任何的想法?
干杯,
每个“共享”按钮,给不同的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>