简体   繁体   中英

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. 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. I must be missing something. Their instructions were to paste this into the HTML, preferably just below the opening <body> , so I did:

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

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

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

That doesn't exist and IT FAILS miserably

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. Without a url or copy of the outputted html, almost impossible to tell. If you are working on a local network and lose your internet connection, for example, boom, no FB Like box.

Taking a shot in the dark- This IS a javascript error. Errors in javascript are not displayed to the screen. 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. 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)

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. Then it's back to the above advice.

Or plugin.

http://www.addthis.com/

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

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