Why don't any of my facebook share buttons work?

405 Views Asked by At

I did what Facebook Developers told me to do. http://jsfiddle.net/desbest/u44e0802/

<!-- initialise -->

<div id="fb-root"></div>

<!-- button 1 -->

<script src="//connect.facebook.net/en_US/all.js"></script>

<div class="fb-send" data-href="http://compesh.com" data-font="trebuchet ms"></div>

<!-- button 2 -->

<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_GB/sdk.js#xfbml=1&version=v2.3&appId=299539706821986";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button"></div>
2

There are 2 best solutions below

0
On BEST ANSWER

Create a localhost internet server like Xampp, Wamp etc

Then you have to write right after opening body tag

<div id="fb-root"></div>

<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 = "https://connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
</script>

CARE: js.src must be https://connect.facebook.net/en_US/sdk.js
______ no //connect.facebook.net/en_US/sdk.js

Then place wherever you want your button writting

<div 
  class="fb-like" 
  data-href="http://www.example.com" 
  data-width="200" 
  data-layout="standard" 
  data-action="like" 
  data-show-faces="true" 
  data-share="false">
</div>
1
On

Copying your code into a local file and running it with XAMPP, it works fine.

When having it run on JSfiddle, looking at the console it's throwing a few errors:

Uncaught SecurityError: Failed to set the 'domain' property on 'Document': Assignment is forbidden for sandboxed iframes.

I'd suggest their security settings are blocking it from running on there. Are you trying it somewhere else where it isn't working?