简体   繁体   English

Facebook“赞”按钮根本不显示

[英]The Facebook “Like” button doesn't show at all

New to coding, so bear with me if this is really basic! 编码新手,如果这真的很基础,请多多包涵! I'm trying to add a FaceBook "like" button to my page. 我正在尝试向我的页面添加FaceBook“喜欢”按钮。 I copied the code exactly as they describe on their instructions site. 我完全按照他们在其说明网站上的描述复制了代码。 I entered my page details, the desired width (it fit the limits of what they recommend for the features I selected in the generator), and so on, and then copied/pasted the code into my html. 我输入了页面详细信息,所需的宽度(它适合在生成器中选择的功能所建议的宽度),等等,然后将代码复制/粘贴到html中。 I must be missing something. 我肯定错过了什么。 Their instructions were to paste this into the HTML, preferably just below the opening <body> , so I did: 他们的指令是将其粘贴到HTML中,最好是在<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>

Then they said to copy/paste the following wherever I wanted the button to show up, which I did: 然后他们说要在我希望按钮出现的任何地方复制/粘贴以下内容,我这样做了:

<div class="fb-like" data-href="http://www.facebook.com/musicbyava" data-send="true" data-layout="button_count" data-width="100" data-show-faces="false" data-font="arial"></div>

I refresh my page, and there's not a trace of anything in the place where the plugin is supposed to be. 我刷新了页面,在该插件应该放置的地方没有任何痕迹。 Not a dot, not a line, not an error message, nada. 不是点,不是线,不是错误消息,nada。 What am I missing? 我想念什么? Thanks in advance! 提前致谢!

The reason it didn't work on your local machine but started to work magically on the server is this: 它在您的本地计算机上不起作用,但开始在服务器上神奇地工作的原因是:

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

the // in front of the code means that the browser should use the protocol in use at the time the script is being loaded... SO: 代码前面的//表示浏览器应在加载脚本时使用所使用的协议...因此:

if you are running http://example.com facebook will load an unsecured one and if your using https://example.com then the script will be loaded from a secure server at facebook... 如果您正在运行http://example.com,facebook将加载不安全的脚本;如果您使用的是https://example.com,则将从facebook上的安全服务器加载脚本...

NOW here's where the magic happened... when loading from a local file your browser displays the URL as file:///C:/mysite so automatically the browser looks for a file called 现在,这就是发生魔术的地方...从本地文件加载时,浏览器将URL显示为file:///C:/mysite因此浏览器会自动查找名为

file:///connect.facebook.net/....

That doesn't exist and IT FAILS miserably 那不存在,IT惨遭失败

guess what happened when you uploaded it to the server??? 猜猜当您将其上传到服务器时发生了什么???

I'll let you figure that one out... 我让你想一想...

Cheers... 干杯...

您在哪种类型的网站上使用fb like按钮(例如joomla或wordpress)进行cms,我认为最好的使用方法是http://sharethis.com/#sthash.OXTxyj48.dpbs很好的选择,如果您喜欢,我也使用了很多次尝试一下,转到站点后,单击“ 获取共享工具”菜单,然后就可以使用它,并将代码粘贴到站点中,

Welcome to Stack Overflow. 欢迎使用堆栈溢出。

There could be an array of problems why the script isn't displaying the like button. 脚本为什么不显示“ like”按钮可能会有一系列问题。 Without a url or copy of the outputted html, almost impossible to tell. 没有输出的html的url或副本,几乎无法分辨。 If you are working on a local network and lose your internet connection, for example, boom, no FB Like box. 如果您在本地网络上工作并且丢失了Internet连接,例如,繁荣,没有FB Like框。

Taking a shot in the dark- This IS a javascript error. 在黑暗中拍摄-这是一个JavaScript错误。 Errors in javascript are not displayed to the screen. javascript中的错误不会显示在屏幕上。 Instead, they manifest themselves in a near infinite amount of ways, from omitting a single element after page load to loading a white screen. 取而代之的是,它们以几乎无限的方式展现自己,从页面加载后省略单个元素到加载白屏。

If you are working with Chrome or Firefox, you can download an Web Developer extension. 如果您使用的是Chrome或Firefox,则可以下载Web Developer扩展。 I recommend Firebug for Firefox, or Right Click and "Inspect Element" in Chrome (I think this ships with Chrome- otherwise it's the Web Developer Extension) 我建议使用Firefox的Firebug,或在Chrome中单击鼠标右键和“检查元素”(我认为这是Chrome附带的,否则就是Web开发人员扩展)

Whichever tool you use, all errors with be outputted in the console of these environments. 无论使用哪种工具,所有错误都会在这些环境的控制台中输出。

And we're just getting started. 我们才刚刚开始。

If this sounds like too much work, I recommend trying the above code on a different page to see if the page you are copy&pasting to has malformed html. 如果听起来工作太多,建议您在其他页面上尝试上述代码,以查看要复制粘贴的页面的html格式是否错误。 Then it's back to the above advice. 然后回到上面的建议。

Or plugin. 或插件。

http://www.addthis.com/ http://www.addthis.com/

我遇到了这个问题,然后将域URL添加到了Facebook开发人员工具中的应用程序设置中: https : //developers.facebook.com/apps/[app_id ]/settings/->设置->基本

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

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