Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

My HTML is almost HTML5-compliant according to the W3C Validator, only one error is remaining: the Javascript code to configure the Google Plus buttons.

Whether I add CDATA or not, the error "The text content of element script was not in the required format: Expected space, tab, newline, or slash but found { instead." is displayed for this line:

<script src="http://apis.google.com/js/plusone.js" type="text/javascript">
   {"lang":"en","parsetags":"explicit"}
</script>
like image 481
richey Avatar asked Jan 18 '13 22:01

richey


2 Answers

The error message is correct. A script tag that has its src attribute set can only contain documentation: whitespace and comments (/* ... */ or //...).

If you just want to avoid the error, you could try creating the script tag with js, as in the asynchronous load example. This doesn't make it valid but at least the initially served html will be without errors and validators won't complain.

like image 119
kapex Avatar answered Oct 20 '22 05:10

kapex


...I sorely doubt you're going to win the validation-war, here.

If you've got a client/boss that is obsessed over validating (rather than being solid code -- because you can totally have flimsy, flaky, valid code), then you can tell them to drop g+, completely.

But Google is using that script tag to load its file, that file is finding the last script tag that loaded, and then using the inner-text for configuration of the program.

Is it completely valid syntax? Not really, no.

Perhaps they might consider trying to work within JS-comments, but really, Google will change this stuff frequently, as they take over the world and evolve web-programming (angular.js is craaazy).

While they aren't perfect, I'd suspect that their code is more solid than just "W3C validator-approved" code.

like image 29
Norguard Avatar answered Oct 20 '22 05:10

Norguard