I shared to give callback with Tweet using Twitter intent API, but however Facebook hold more number of registered users so I'm going to share the same with Facebook. Facebook have a huge developers' tools which could be helpful to create uncountable tools for websites and apps.
So in one of them is Javascript SDK which uses client-side to do functions, so lets begin:
Make sure that this will not work in any online code editor because it needs a domain or sub-domain to work.
So to start you need a basic work-pattern, following code with load the Javascript SDK:
<script>Then, you need a share dialog with a specific URL on timeline so lets add FB.ui function which initiate a dialog box.
window.fbAsyncInit = function() {
// All functions will go here
};
(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/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
FB.ui({
method: 'share',
href: 'https://developers.facebook.com/docs/', // URL to be shared}, function(response){
// Callback function after shared.});
<span id='fb-share'>Share</span>
<script>
window.fbAsyncInit = function() {
FB.ui({
method: 'share',
href: 'https://developers.facebook.com/docs/', // URL to be shared }, function(response){
// Callback function after shared.});
};
(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/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Post A Comment:
0 comments: