Exploring Google's +1 Button, I found two things odd about the code they supply:
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
{lang: 'en-GB'}
</script>
<g:plusone size="tall" href="http://www.google.com"></g:plusone>
So I have two questions:
First: How is Google able to use the text between the script
tags?
Second: Is the syntax <g:plusone ...
HTML valid? What's this called?
As Google puts it: “The 1+ button is shorthand for 'this is pretty cool' or 'you should check this out. ' Click +1 to publicly give something your stamp of approval.
A personalized button displays profile information for the first Google session that approves your website.
How is Google able to use the text between the script tags?
<script>
elements are perfectly visible in the DOM:
<script type="text/javascript">//FIRST SCRIPT BLOCK</script>
<script type="text/javascript">
var s= document.getElementsByTagName('script')[0];
alert(s.textContent); // "//FIRST SCRIPT BLOCK"
</script>
Google's sneaky trick is to put content in a <script>
that has an external src
. In this case the src
overrides the content inside the block and executes the external script instead, but the contents of the <script>
element are still readable through the DOM even though they do nothing.
Is the syntax
<g:plusone
... HTML valid? What's this called?
No. If they made their own doctype for HTML+plusone it could be valid that, but it doesn't satisfy validity for HTML, and it isn't even namespace-well-formed in an XHTML document, unless you add an extra xmlns:g
for it too.
Is the syntax
<g:plusone
... HTML valid?
No
What's this called?
Invalid psuedo-namespaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With