Facebook - 分享按钮 - 设置文本,标题

时间:2014-03-17 02:17:02

标签: jquery html facebook share

我在列表中有一些博客文章 - 我想为每个帖子创建一个共享链接,我得到以下内容:

<span data-fbTitle="Diamond Energy" data-fbText="Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus." class="fbLink"> Share</span>

JS:

$('.fbLink').click(function() {
    var title = $(this).data('fbTitle');
    var text = $(this).data('fbText');
    window.open('http://www.facebook.com/sharer/sharer.php?p[url]=http://urlplaceholder.com&p[title]=' + title + '&p[summary]=' + text, 'facebook_share', 'height=320, width=640, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');    
});

新窗口打开但没有正确的数据..我需要什么结构的共享网址?我已经搜索过,但有许多旧的,已弃用的链接

招呼

2 个答案:

答案 0 :(得分:1)

现在我使用以下方法,效果很好:

https://developers.facebook.com/docs/javascript/reference/FB.ui/

Basic setup首先,然后:

FB.ui(
  {
    method: 'feed',
    name: 'Facebook Dialogs',
    link: 'https://developers.facebook.com/docs/dialogs/',
    picture: 'http://fbrell.com/f8.jpg',
    caption: 'Reference Documentation',
    description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
  },
  function(response) {
    if (response && response.post_id) {
      alert('Post was published.');
    } else {
      alert('Post was not published.');
    }
  }
);

答案 1 :(得分:0)

尝试使用 .attr()

var title = $(this).attr('data-fbTitle');
var text = $(this).attr('data-fbText');

您也有拼写错误,在连接title内的值时,您需要使用titel而不是window.open()