Facebook Share
// Place following script in header or start of view
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<fb-app-id>',
channelUrl: '<channel-url> //optional',
status: true,
xfbml: true
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
// Use this link in your html section, to share current page
<a href="#" onClick="publishOnFacebook()">Share on Facebook</a>
// Put this function in footer or end of view
<script>
function publishOnFacebook() {
FB.ui(
{
method: 'feed',
name: '<post-name>',
link: '<current-url>',
picture: '<picture-url>',
caption: '<caption-text> //usually website name',
description: '<post-description-text>'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
</script>