简体   繁体   English

Facebook分享按钮不会显示

[英]Facebook share button does not show up

I want to add a very basic facebook share button as it is suggested here : 我想添加一个非常基本的Facebook分享按钮,如下所示:

https://developers.facebook.com/docs/plugins/share-button?locale=fr_FR 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. 问题是按钮不会简单地显示,没有javascript或网络错误。

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. 代码中包含的javascript是加载SDK javascript的内容。

The problem I faced was that I was looking at the html page without going through a web server. 我遇到的问题是我在没有通过Web服务器的情况下查看html页面。 In other words, I was using the file:// protocol and the facebook SDK doesn't work when run under that protocol. 换句话说,我使用的是file://协议,并且在该协议下运行时,facebook SDK不起作用。 Although it does pull a lot of stuff in and affect the DOM, the Facebook share button does not show up. 虽然它确实吸引了很多东西并影响了DOM,但Facebook分享按钮却没有显示出来。

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. 将其设置为仅在localhost(在我的情况下,IIS)中运行真正的Web服务器,并且显示按钮。 Hopefully that will help some folks. 希望这会对一些人有所帮助。

The first line tells you to add the sdk javascript which you havent done. 第一行告诉你添加你没做过的sdk javascript。 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. 到按钮的div标签,它显示。

BTW, based on the documentation , there is no medium size avaialable. BTW,根据文档 ,没有中等大小可用。

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

I had to add "http:" to url in addition to changing "sdk.js" to "all.js" as suggested above, ie: 除了如上所述将“sdk.js”更改为“all.js”之外,我还必须将“http:”添加到url,即:

Instead of: 代替:

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

Use: 采用:

js.src = " http://connect.facebook.net/en_US/all.js#xfbml=1 "; 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. 第1步:获取Share按钮将存在的域的Facebook App ID。 STEP 2: Add the Facebook JavaScript SDK to your Web page. 第2步:将Facebook JavaScript SDK添加到您的网页。 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 第3步:添加代码以在Web页面上加载jQuery库第4步:添加一些jQuery和fb.ui代码以显示“共享”对话框

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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