Вопрос

i got a few blog post's in a list - i want to create for each post a share link, i got the following:

<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');    
});

new window opens but not with the correct data .. what structure do i need for the share url ? i already searched but there are many old, deprecated links

greets

Это было полезно?

Решение

now im using the following method, works perfect:

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

Basic setup first, then:

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.');
    }
  }
);

Другие советы

Try to use .attr()

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

You also has a typo, you need to use title instead of titel when concatenate the value inside window.open().

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top