Addthis & HTML5: Workaround, JS Hack
In einem Projekt sollte ich addthis verwenden. Leider ist der addthis Code nicht HTML5 konform. Die Attribute addthis:url und addthis:title verhindern, dass die Seite mit dem W3C Validator validiert werden kann:
Attribute addthis:url is not serializable as XML 1.0. Attribute addthis:title is not serializable as XML 1.0. Attribute addthis:url not allowed on element a at this point. Attribute addthis:title not allowed on element a at this point.
Daher habe ich einen kleinen jQuery Hack gemacht, der dieses Problem behebt. Es ist einfach: ich verwende Attribute wie data-addthis-url und wandle die dann per Javascript wieder in addthis:url um.
Und so gehts:
Ürsprünglicher Code:
<div class="wrapper"> <a href="#" class="addthis_button" addthis:url="http://example.com" addthis:title="An Example Title">Example</a> <a href="#" class="addthis_button" addthis:url="http://test.com" addthis:title="An Example Title">Test</a> </div>
Neu:
<div class="wrapper"> <a href="#" class="addthis_button" data-addthis-url="http://example.com" data-addthis-title="An Example Title">Example</a> <a href="#" class="addthis_button" data-addthis-url="http://test.com" data-addthis-title="An Example Title">Test</a> </div> <script type="text/javascript"> $(document).ready(function(){ $(".wrapper").find('[data-addthis-url]').each(function(index){ $(this).attr("addthis:url",$(this).attr("data-addthis-url")); $(this).removeAttr('data-addthis-url'); $(this).attr("addthis:title",$(this).attr("data-addthis-title")); $(this).removeAttr('data-addthis-title'); }); }); </script>
Das wärs!
Moin,
anscheinend hat da AddThis irgendwie dran gebastelt, die von dir genannten Attribute funktionieren auch auf Anhieb.