简体   繁体   中英

Facebook share button does not show up

I want to add a very basic facebook share button as it is suggested here :

https://developers.facebook.com/docs/plugins/share-button?locale=fr_FR

The problem is the button does not simply show up, no javascript or network errors.

Can anyone say me what i'm doing wrong ?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>titre</title>
</head>
<body>
<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 = "//connect.facebook.net/en_US/all.js#xfbml=1";
  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>


</body>
</html>

Thanks in advance for your help

The marked answer is silly. The javascript included in the code is what loads the SDK javascript.

The problem I faced was that I was looking at the html page without going through a web server. In other words, I was using the file:// protocol and the facebook SDK doesn't work when run under that protocol. Although it does pull a lot of stuff in and affect the DOM, the Facebook share button does not show up.

Setting it up to run through a true web server on just localhost (in my case, IIS) and lo-and-behold the button shows up. Hopefully that will help some folks.

The first line tells you to add the sdk javascript which you havent done. Do the following and you should be good to go:

<script type="text/javascript" src="Location of SDK javascript"></script>

For me it was the size attribute that prevented the button from showing.

Just add

data-size="large"

to the div tag for the button and it shows.

BTW, based on the documentation , there is no medium size avaialable.

有时看到Facebook按钮的这些问题是因为像Disconnect这样的浏览器扩展阻止了与Facebook通信的脚本等,所以如果是这样的话,请将您的网站列入白名单。

I had to add "http:" to url in addition to changing "sdk.js" to "all.js" as suggested above, ie:

Instead of:

js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1";

Use:

js.src = " http://connect.facebook.net/en_US/all.js#xfbml=1 ";

Good Luck

STEP 1: Get a Facebook App ID for the domain the Share Button will live on. STEP 2: Add the Facebook JavaScript SDK to your Web page. STEP 3: Add code to load the jQuery library on your Web page STEP 4: Add some jQuery and fb.ui code to display the Share dialog box

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM