ziiweb ziiweb - 3 months ago 6
Javascript Question

Where should I place the Facebook Like Javascript code?

It is said that javascript code must be place righ before the

</body>
tag. But after generating the Facebook Like button I get this message:


Include the JavaScript SDK on your page once, ideally right after the
opening
<body>
tag.


This is the code I have to add:

<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&appId=675640525783719";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

Answer

Do as they say, put it rigth after the opening <body> tag:

<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&appId=675640525783719";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

//rest of your code

</body>
</html>
Comments