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?
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.
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