MANY FACEBOOK SHARE buttons in the same page?

送分小仙女□ 提交于 2019-12-01 05:15:04

问题


I implemented the facebook share button in my page using javascript, like this:

<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>

It is working pretty well but now I'd like to put many posts within the same page and use a different share button for each post (very FB share button shall have a different link, title and image). Any ideas?

It worked with the like button, using the 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>  

But how to do a similar thing with the share_button? Any idea?

Cheers,


回答1:


Give each of your "share" button a different id and alter the other options(different link, title and image) for each item.
For example:

<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>

The buttons could be:

<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>


来源:https://stackoverflow.com/questions/14111177/many-facebook-share-buttons-in-the-same-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!