Google Plus 1 Button W3C konform einbinden
Dienstag, 19 Juli 2011 3 Kommentare
zugegeben, so richtig elegant ist meine Art des Einbindens nicht - aber imerhin hat der Validator nichts mehr zu meckern und die Seite validiert. Das kriegt man mit etwas Javascript hin.
Man nehme einige Javascripts, die man unten vor den abschließenden Body-Tag setzt:
< script type="text/javascript" src="http://apis.google.com/js/plusone.js"> < /script>
< script type="text/javascript" src="http://www.google.com/jsapi"> {lang: 'de'}< /script>
< script type="text/javascript"> google.load("jquery", "1");< /script>
< script type="text/javascript" src="js/plusone.js"> < /script>
Zuerst die Google API für den Plus-Button, dann jQuery vom Google-Server, den Lade-Befehl für jQuery und zuguterletzt ein eigenes Stück Javascript, das wir gleich herstellen werden
Dort auf der Seite, wo der Button hin soll, schreiben wir ein DIV mit der ID gplus.
Wir legen uns nun eine neue Datei an, und nennen Sie plusone.js, ich habe Sie in den Unterordner js geschoben. Darin notieren wir etwas jQuery-Code. Genauer: Wir sorgen dafür, das beim Laden des Dokuments in den DIV mit der ID gplus der Google-Plus Code notiert wird.
$(function(){
$('#gplus').append('< g:plusone size="normal"
href="http://www.seitoskop.de" count="false">
< \/g:plusone> ');
});
Mit dem Attribut count gibt man an, ob die Anzahl Votes angezeigt wird (true) oder nicht (false). Size wird für die Größe gebraucht.
This is a nested column
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
This is another nested column
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Das Problem ist dass schon die Landesangabe folgenden Fehler des Validator (CSE v9.03) auslöst: The script content will be ignored because the "script" tag has a "src" attribute. In this case, the script referenced by the "src" attribute will be used and the content of "script" will be ignored (per the HTML/XHTML specification).
Danke für den Hinweis. Auf die Idee den Code einfach in ein Javascrpt zu packen bin ich noch gar nicht gekommen.
Es geht auch ohne Skript nur mit HTML: thesoundofklee.de/PRyEV