Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Facebook share success?

I'm looking to detect if a Facebook share on a page was successful, and upon success change the value of a box. I can handle the latter just fine, but am a little lost as to how execute the actual share detection. I've Google and found FB.ui, but how do I actually implement it into a page and have it run the detection?

like image 718
David Winsauer Avatar asked Oct 21 '22 00:10

David Winsauer


1 Answers

Firstly you must include Facebook sdk.js library to use all its methods (ideally right after the opening of body tag)

<script>
(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>

The problem with your http://jsfiddle.net/ysdp60cz/ is the scope of the facebookShare var. So, in this example, just include it in the window object:

window.facebookShare = function( callback ) { [...]

I don´t know how are you organizing your code, however, with this changes it must work.

You can check it here: http://jsfiddle.net/benjasHu/3dhq9k21/

Cheers.

like image 74
benjasHu Avatar answered Oct 27 '22 10:10

benjasHu