Re: HTML 5 parser creating multiple body elements

Thomas Broyer wrote:
> On Thu, Jul 16, 2009 at 2:41 PM, Geoffrey Sneddon wrote:
>> Given the following:
>>
>> <!doctype html>
>> <script>
>> document.documentElement.innerHTML = "<body bgcolor=green>";
>> </script>
>> <body bgcolor=red>
>>
>> The HTML 5 parser creates:
>>
>> doctype
>> html
>>        head
>>        body@bgcolor='green'
>>        body@bgcolor='red'
>>
>> It would be desirable not to create multiple body elements.
> [...]
>> None of these options seem very nice (HTML5 because it results in multiple
>> body elements; Firefox/Chromium as they result in a text node child of the
>> HTML element; Opera because it results in a P element child of the HTML
>> element; IE because it disallows innerHTML). As IE throws when trying to set
>> innerHTML on the HTML element (which, AFAIK, is the only case in which this
>> can occur), I find it doubtful any sites depend on any specific behaviour,
>> though it seems nicest to avoid having multiple body elements, and treating
>> it closer to two body elements in the token stream.
> 
> How about changing step 2 in setting innerHTML to "If the node's
> document has an active parser"? (instead of "If the attribute is being
> set on a Document node, and that document has an active parser")
> It wouldn't match any browser but as you said, given that IE throws,
> it is "doubtful any sites depend on any specific behaviour".

That cannot be done, as it has huge consequences for any setting of 
innerHTML while parsing (i.e., it will always fail).

For example, a perfectly safe setting of innerHTML, would then fail:

<!doctype html>
<p>Foo</p>
<script>
document.getElementsByTagName("p")[0].innerHTML = "Bar";
</script>

Sites rely upon things like that working, so your proposed change is 
unworkable. The changes that need to be made are at a tree builder 
level, as far as I can tell.

-- 
Geoffrey Sneddon — Opera Software
<http://gsnedders.com/>
<http://www.opera.com/>

Received on Thursday, 16 July 2009 15:52:17 UTC