Bug 60316

Summary: Implement document.innerHTML
Product: WebKit Reporter: Andy Estes <aestes>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED WONTFIX    
Severity: Enhancement CC: abarth, aestes, ap, darin, eric, ian, mathias, rafaelw
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch none

Description Andy Estes 2011-05-05 16:57:24 PDT
HTML5 includes an innerHTML attribute in the HTMLDocument interface definition, which should basically behave like the innerHTML on Element. See <http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-html-documents.html#dom-innerhtml> for details.

The most interesting difference between Document's innerHTML and Element's innerHTML is that the Document case is the only time when parsing a fragment should have no context element. This is important since we have implemented several optimizations to fragment parsing that assume there is always a context element, but there won't be in this case.

In a W3C bug discussing context-less fragments, it was mentioned that document.innerHTML is prescriptive, rather than descriptive of existing web content. See <http://www.w3.org/Bugs/Public/show_bug.cgi?id=12031>.
Comment 1 Andy Estes 2011-05-05 17:10:05 PDT
Created attachment 92505 [details]
Patch
Comment 2 Eric Seidel (no email) 2011-05-05 17:11:00 PDT
Comment on attachment 92505 [details]
Patch

OK.  I would have said "if".  I'm not sure we want to implement document.innerHTML.
Comment 3 Andy Estes 2011-05-05 17:11:19 PDT
(In reply to comment #2)
> (From update of attachment 92505 [details])
> OK.  I would have said "if".  I'm not sure we want to implement document.innerHTML.

Sure, I'll change that.
Comment 4 Andy Estes 2011-05-05 17:12:52 PDT
Committed r85903: <http://trac.webkit.org/changeset/85903>
Comment 5 Alexey Proskuryakov 2011-05-05 22:16:00 PDT
A read-only document.innerHTML would be a handy shortcut for (new XMLSerializer).serializeToString(document).

What's the difference between parsing for document.innerHTML setter and DOMParser.parseFromString()? Do we really want them to be different?
Comment 6 Eric Seidel (no email) 2011-05-05 22:22:33 PDT
Sounds like a question for Hixie (probably in the w3c bug).
Comment 7 Alexey Proskuryakov 2011-05-05 22:41:54 PDT
Note that HTML5 doesn't specify DOMParser and XMLSerializer.
Comment 8 Ian 'Hixie' Hickson 2011-05-06 11:11:12 PDT
It's just a convenience accessor so you can replace the contents of an existing document more easily.

DOMParser and company are being specced here, FWIW:
   http://html5.org/specs/dom-parsing.html
Comment 9 Alexey Proskuryakov 2011-06-18 12:15:04 PDT
Only a FIXME has been landed, and this bug is still unresolved.
Comment 10 Alexey Proskuryakov 2011-06-18 12:22:12 PDT
The reason why I'm asking about DOMParser here is that it works without triggering this assertion. If document.innerHTML is going to trigger it, then maybe its specification is incorrect.
Comment 11 Mathias Bynens 2012-02-08 06:46:29 PST
The spec has moved to http://html5.org/specs/dom-parsing.html#innerhtml, and sadly, `document.innerHTML` has been removed.
Comment 12 Eric Seidel (no email) 2012-02-08 08:46:09 PST
Yay!  So you're saying we can remove this support from the parser. :)  (Which should simplify things again.)
Comment 13 Alexey Proskuryakov 2012-05-17 10:34:55 PDT
What's the status of this bug now, given bug 84646?
Comment 14 Rafael Weinstein 2012-05-17 10:52:22 PDT
I'd say it's safe to close it. Document.parse() is now the consensus recommendation for contextless parsing.
Comment 15 Alexey Proskuryakov 2012-05-17 11:14:03 PDT
Let's close it then!
Comment 16 Rafael Weinstein 2012-05-17 11:33:21 PDT
Hazzah!