I personally avoid facebook's javascript lib and widgets although I don't think they are that bad to implement.
Facebook does support a non-javascript option for sharing a link to facebook. This is what I prefer to use.
Share to facebook without javascript
Share link looks like this:
https://www.facebook.com/sharer/sharer.php?u=[URL-TO-SHARE-GOES-HERE]
You would replace [URL-TO-SHARE-GOES-HERE]
with the URL you want to share. Example:
https://www.facebook.com/sharer/sharer.php?u=https://example.com
On your page you would create a share button like this:
<a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com" target="_blank">
<img src="[facebook-share-button]" />
</a>
[facebook-share-button]
should be a url to the "custom button" you want the user to click on.
URL-encode the url (http://example.com) before adding it as a parameter. Otherwise more complicated URLs may not get shared properly. You can encode the url on the server side in your Content Management System (CMS) before returning the html to the user, or you can do it with javascript (encodeURIComponent
).
Which image shows up on facebook for the link?
This post answers in detail: How does Facebook Sharer select Images and other metadata when sharing my URL?
Basically you add specific meta tags to the <head>
section of your pages. This allows you to specify the image(s) to display explicitly.