0

I want to build a share button for a certain URL, but I want to keep my solution as simple as possible. I would like to avoid having to import any JS framework or toolkit from their SDK to do this.

For instance, in Twitter, I can get that same result with this code:

<a href="https://twitter.com/intent/tweet?text=${myTextVariable}&url=${myUrlVariable}">Share</a>

In here I can customize the URL and the predefined text that the tweet will contain.

Is there an analog way to achieve this for facebook?

Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189

1 Answers1

1

Just use sharer.php:

<a href="https://www.facebook.com/sharer.php?u=[encoded-url]">linktext</a>

You can only share links, and you cannot prefill the message, of course. That would not be allowed anyway (see platform policy). Also, Open Graph tags will be taken from the source of the shared URL.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • I did not know that the title could not be prefilled. Could you give me a URL reference to that topic? – Enrique Moreno Tent Jun 11 '19 at 19:36
  • there´s a ton of stackoverflow threads about that already...for example: https://stackoverflow.com/questions/20956229/has-facebook-sharer-php-changed-to-no-longer-accept-detailed-parameters – andyrandy Jun 11 '19 at 20:15
  • with sharer.php, it is not possible to prefill the title since many years. with other options (like fb.ui feed, for example), it was disabled a while ago too. – andyrandy Jun 11 '19 at 20:17
  • luschn: The question in itself is not about "sharer.php", but if there are any ways to achieve that goal. – Enrique Moreno Tent Jun 11 '19 at 21:06
  • i know, see the other comment. it is no longer possible even with other options like fb.ui feed, there was a workaround but it´s been fixed. – andyrandy Jun 11 '19 at 21:12