[Javascript] Strictly speaking (Was Javascript Detection)
Nick Fitzsimons
nick at nickfitz.co.uk
Wed Jan 3 14:06:57 CST 2007
On 3 Jan 2007, at 19:05:47, Matt Warden wrote:
> On 1/3/07, Paul Novitski <paul at juniperwebcraft.com> wrote:
>> At 1/3/2007 06:31 AM, Matt Warden wrote:
>> >I find DOM manipulations to be elegant, once you wrap your ahead
>> >around the fact that this is *not* markup anymore, but rather an
>> >active document, represented by a tree structure.
>>
>> I've always considered document.write() to be sloppy, DOM-less
>> coding, however the manual does say:
>>
>> "The text you write is parsed into the document's structure model. In
>> the example above, the h1 element becomes a node in the document."
>> http://developer.mozilla.org/en/docs/DOM:document.write
>
> I'm not sure how else it would work. I can't think through my head how
> the markup itself could just be inserted as a text node but somehow
> still function as part of the document.
>
I recently did a number of tests focused on this very issue (in
relation to the WaSP's DSTF's invitation to assist the IE Team in
prioritising DOM fixes for IE.next), and the conclusion I came to was
that the string assigned to the innerHTML property is indeed passed
through the HTML parser, at least on IE (and I assume on all
browsers). I was able to prove this by triggering certain bugs in
IE's parser when inserting supposedly-valid markup.
One interesting side effect of this is that
someElement.innerHTML = someMarkup;
insertedMarkup = someElement.innerHTML;
return insertedMarkup == someMarkup;
doesn't necessarily return true; indeed, doing a more accurate
comparison by walking the resultant DOM tree, allowing for things
like capitalisation of tag names and attributes being unordered, will
reveal that the DOM created by the parser won't necessarily be the
same as if the equivalent DOM creation and manipulation methods are
used.
I'm still getting the results of the tests (which also cover assorted
DOM oddities which modify the parser's behaviour on subsequent
insertions of the same markup) written up, and will post a link when
ready, for those who are interested.
Regards,
Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/
More information about the Javascript
mailing list