FB Like/Share button script giving me validation error

I added some social button to two websites. They now won’t validate due to the Facebook script. The error says.

The text content of element script was not in the required format: Expected space, tab, newline, or slash but found { instead.

The script looks like this

<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_GB/sdk.js#xfbml=1&version=v2.3";
                                  fjs.parentNode.insertBefore(js, fjs);
                                }(document, 'script', 'facebook-jssdk'));</script>
                                
                                <div id="fbsh"><div class="fb-like" data-href="http://www.example.com" data-layout="button" data-action="like" data-show-faces="false" data-share="true"></div></div>

The line it referrs to is the last one in the script.
Does anyone know what’s wrong with it, or how to fix?

Have you added your ID to the code on your site?

js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.3&appId=<your-16-digit-app-id>";

No. It seems I missed that, it wasn’t mentioned on the instructions.

Where does this number come from? I don’t have an app, its just a website.
This is where I’m getting the code, there is no mention of adding id numbers.

You need to sign up : https://developers.facebook.com/

Create a new app (top left ‘my apps’) and it’ll give you a ID to use.

According to the FAQ I don’t need an account or an app to use social plugins on a web page.

When I last tried to validate the site which is giving me 403 it was using the W3C validator, not the nu html checker which you get now. Then it was all OK apart from the FB Like button script (not my code) FB Like/Share button script giving me validation error

Off Topic:

@SamA74

To prevent Javasript validation errors I use the html remark tags.

<script>
<!--
// JavaScript stuff goes here
-->
</script>

// that took 18 keystrokes to add the code block :frowning:

Thanks, I will look into that… at least when the validator actually works.

Yes, the validator isn’t happy with < eg.

if (var_a < var_b) 
1 Like

I couldn’t reproduce that error. This is what I put into the validator, both new and old.

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script>
if (var_a < var_b) alert("Test")
</script>
</head>
<body>
<p></p>
</body>
</html>

Ahh, yes, because XHTML. That’s why we used <![CDATA[ tags in XHTML.

I tried commenting the problem script:

<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_GB/sdk.js#xfbml=1&version=v2.3";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk')); -->
</script>

And I still get 403 from the validator, plus the buttons are now missing from the site.

BTW @John_Betong and others, would you prefer to continue this subject in my other thread, so as not to hijack yours with my problem?

Posts merged from this thread.

Interesting. It looks to be doctype or maybe “nu” related.
When I used

<!DOCTYPE html 
       	PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
	'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>

It gives

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.