I'm trying to execute callback function in FB.ui (send dialog). It called in same moment when loaded FB.ui but I want execute callback function after pressing 'send' or 'cancel' button. Is it realizable?
function callback(response) {
alert('message was sent');
}
FB.ui({
method: 'send',
name: 'Dialog',
link: 'http://***.com',
redirect_uri: '****',
description: '***',
picture: '***',
to: userId
},
callback(response)
);
The callback requires a function as a parameter. Here, you are actually calling the function.
Facebook will actually call the function that you pass it along with the response.
Rather than passing "callback(response)" as the callback parameter, just pass "callback" like this:
function callback(response) {
alert('message was sent');
}
FB.ui({
method: 'send',
name: 'Dialog',
link: 'http://***.com',
redirect_uri: '****',
description: '***',
picture: '***',
to: userId
},
callback
);
Issue has probably been solved or is irrelevant to OP, but this might help some others out that stumble upon the post.
Similar to Mike Jerema's comment on Fisch's reply (Unable to comment there due to insufficient rep):
The response callback receive from the user interacting with the send dialog returns one of three things:
Therefore the correct code to handle this callback for all use cases would be:
var callback = function(response) {
if (response instanceof Object)
{
//Send clicked
}
else if (response === null)
{
//Cancel clicked
}
else
//X clicked
};
Hope this helps! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With