2015-12-02 59 views
2

我有一个包含许多图像的网页。每个图片上都有一个Facebook分享按钮和一些说明。我想要做的是,当用户点击分享按钮时,相应的图片和该特定图片的描述将在Facebook上分享。多个Facebook分享按钮在同一页

我一直在看Facebook的文档,到目前为止我的理解是,Facebook需要链接您想要共享的页面,并从中选择一个图像,这显示在共享文章上。

有没有一种方法可以指定图像的URL和共享文章中的描述文字?

+0

其实你不能使用共享按钮。 还有一个类似的问题: http://stackoverflow.com/questions/22877149/creating-a-facebook-share-button-with-customized-url-title-and-image – cesare

回答

0

在共享url中,您可以指定要共享的图像的div,并为每个共享按钮创建一个EventListener。

//add event listener to the first share button 
document.getElementById('share_btn1').addEventListener('click', function() { 
    FB.ui({ 
     method: 'share_open_graph', 
     action_type: 'og.likes', 
     action_properties: JSON.stringify({ 
      object:'http://yourdomain.com/share.php#div_img1', 
     }) 
    }, 
    function(response){ 
     // Debug response (optional) 
     console.log(response); 
    }); 

}, false); 


//add event listener to the second share button 
document.getElementById('share_btn2').addEventListener('click', function() { 
    FB.ui({ 
     method: 'share_open_graph', 
     action_type: 'og.likes', 
     action_properties: JSON.stringify({ 
      object:'http://yourdomain.com/share.php#div_img2', 
     }) 
    }, 
    function(response){ 
     // Debug response (optional) 
     console.log(response); 
    }); 

}, false); 
相关问题