The whole explanation, or are there some specific parts you don't like?
Originally Posted by jscheuer1
I've had a cursory glance, though I'd reformat the code before critiquing it: if you want critiques, making the code pretty first would be nice.
So, in addition to any critique of the code, [...]
I don't like the escaped new lines in the initial string literal: these are actually illegal, though tolerated in most browsers. I'd either settle for string concatenation or joining an array (below). The two other escapes are unnecessary, too - the first always is, no matter how the script is included.
As someone might call a "box" mybox, you should declare the global with the same name properly using a variable declaration. If you don't, an exception will occur in MSIE as it will create its own read-only global. A variable declaration will give priority to the script - this is why globals should always be explicitly declared.
' position: absolute;',
' top: -80000px;',
' left: -80000px;',
Not a problem, but curious: why use the DOM 0 Image constructor function if you're depending upon the DOM 1 createElement method? It seems strange to mix the two unnecessarily.
I'm sure you know that I'd appreciate feature detection and a defensive style, which seems absent.
The regular expression could be simplified to:
The initialisation portion of the for loop that follows is redundant.
The default for getAttribute in MSIE is a case-insensitive attribute search so the second (kludgy) argument isn't necessary. However, I would recommend that you drop use of the method entirely and use property equivalents.
Rather than obtain the value of the rel attribute repeatedly, cache the value and avoid the overhead of all of those method calls (or property look-ups). This applies to similar code patterns.
Drop the call to overrideMimeType and the related code. As discussed previously, this method is really only of use when wanting to have the response parsed as XML so that the responseXML property can be used to access the document using DOM methods. If you're only using the responseText property, attempting to change the media type is redundant.