Facebook like and share button with callback
You cannot get the share callback using this like button. You can instead create a share button of yours and invoke the Feed Dialog on its click-
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.'); }});
full code is here
$("#bodyarea").on('click', '.share_fb', function(event) { event.preventDefault(); var that = $(this); var post = that.parents('article.post-area'); $.ajaxSetup({ cache: true }); $.getScript('//connect.facebook.net/en_US/sdk.js', function(){ FB.init({ appId: '822306031169238', //replace with your app ID version: 'v2.3' }); FB.ui({ method: 'share', title: 'TTitle Test', description: 'Test Description Goes here. Tahir Sada ', href: 'https://developers.facebook.com/docs/', }, function(response) { if (response && !response.error_code) { alert('Posting completed.'); } else { alert('Error while posting.'); } }); });});
Change your application id to work
An alternative way I made here to who don't want to publish an APP just for it is:
jQuery("#div_share").click(function() { var url = "http://www.facebook.com/sharer/sharer.php?u=YOUR_URL&title=YOUR_TITLE"; var openDialog = function(uri, name, options, closeCallback) { var win = window.open(uri, name, options); var interval = window.setInterval(function() { try { if (win == null || win.closed) { window.clearInterval(interval); closeCallback(win); } } catch (e) { } }, 1000); return win; }; openDialog(url,'Facebook','width=640,height=580', function(){ jQuery("#div_share").hide(); jQuery("#formulario").show(); }); });
It will open a javascript dialog to share, and know when the user close it. It's not guaranteed that they really share the content... but.. :)