FB.ui problems with Feed Dialog, Many dialog boxes open at once

1.2k Views Asked by At

I'm developing a facebook app in javascript and I have a problem to use FB.ui to open a dialog to share on the facebook wall. I have this code:

$('#share_button').click(function(){
FB.ui(
{
    method: 'feed',
    name: photo.getName(),
    link: photo.getUrlView(),
    picture: +photo.getUrl(),
    caption: photo.getCaption(),
    description: photo.getDescription()
},
function(response) {
    if (response && response.post_id) {
        alert('Post was published.');
    } else {
        alert('Post was not published.');
    }
}
)
});

the values (name,descripton, picture, link, caption) going to refresh with js when I click on other link. When I click on to share the content on the first time, all its OK, but when the content is changed and I share the new content, Facebook shows the new dialog, but also shows the old...open all previous windows.

1

There are 1 best solutions below

1
On

Probably, this issue happen because you are binding a callback to the click event many times...

When you click on another link to refresh the Facebook dialog content, you bind the click event to show the dialog, if you bind the click event again, there are two callbacks binded to the click event of your Share button, then, two dialogs are showed, because two callbacks are called on the clicked event.

To solve this, you need to clean the callbacks binded to the click event before bind the new callback, so, your code should looks like this:

$('#share_button').unbind("click");
$('#share_button').click(function(){
    ...
});

Hope this help!