Facebook like and share button with callback

前端 未结 4 1087
闹比i
闹比i 2020-12-04 16:03

I have a webpage where I have placed a Facebook like & share button and corresponding javascript callback functions are also present.

Now the problem is, the jav

4条回答
  •  萌比男神i
    2020-12-04 16:37

    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

    Working Example

提交回复
热议问题