/ Hacking the Technorati Badge part Deux

The code below is out of date. For the latest version see document.write() fix for (real) XHTML
In my previous post on Hacking the Technorati Badge I told the tale of how I managed to get it working with the application/xhtml+xml MIME type. Since then I tweaked the technique and managed to get rid of the extra <script> tag immediately preceding the XHTML element you want badge to appear in. I was able to do this by identifying the word “technorati” in the src attribute of the <script> tag and then inserting the contents of the badge immediately next to it.

Here’s the updated code:

var Utils = {
	DW : function(str){
		var s = document.body.getElementsByTagName("script");
		for(var i=0; i < s.length; i++){
			if(s[i].getAttribute("src").toLowerCase().indexOf("technorati") != -1){
				str = Utils.CleanTechnorati(str);
				s[i].parentNode.innerHTML += str;
	CleanTechnorati : function(str){
		return str.substring(0, str.indexOf("&#187")+5) + ";" + str.substring(str.indexOf("&#187")+5, str.length);
document.write = Utils.DW;

The reason for this is because about a day after I implemented the fix I noticed my Silktide score go down by .6 points. When I looked into it I saw that it’s because according to the British Disability Discrimination Act you can’t have <script> tags directly in the page’s <body> (this makes no sense since the Technorati badge is inserted via a <script> tag). And since this code is found on all of my pages, it hit my score pretty hard. So out goes the extra <script> tag.

Now to see what I can do about badges with multiple document.write()s


Read more from the archive.