HTML Standard Tracker

Filter

File a bug

SVNBugCommentTime (UTC)
2034Define outerHTML for HTML elements in HTML documents.2008-08-10 22:23
@@ -6605,50 +6605,56 @@ http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20HTML%3E%0
    </dd>
    
 
   </dl>
 
 
   <h3><dfn>Dynamic markup insertion</dfn></h3>
 
   <p>The <code title="dom-document-write">document.write()</code>
   family of methods and the <code
-  title="dom-innerHTML">innerHTML</code> family of DOM attributes
+  title="dom-innerHTML">innerHTML</code>/<code
+  title="dom-outerHTML">outerHTML</code> family of DOM attributes
   enable script authors to dynamically insert markup into the
   document.</p>
 
   <p>Because these APIs interact with the parser, their behavior
   varies depending on whether they are used with <span>HTML
   documents</span> (and the <span>HTML parser</span>) or XHTML in
   <span>XML documents</span> (and the <span>XML parser</span>). The
   following table cross-references the various versions of these
   APIs.</p>
 
   <table>
    <thead>
     <tr>
      <td></td>
-     <th><dfn title="dom-document-write"><code>document.write()</code></dfn></th>
-     <th><dfn title="dom-innerHTML"><code>innerHTML</code></dfn></th>
+     <th>For documents that are <span>HTML documents</span></th>
+     <th>For documents that are <span>XML documents</span></th>
     </tr>
    </thead>
    <tbody>
     <tr>
-     <th>For documents that are <span>HTML documents</span></th>
+     <th><dfn title="dom-document-write"><code>document.write()</code></dfn></th>
      <td><span title="dom-document-write-HTML"><code>document.write()</code> in HTML</span></td>
-     <td><span title="dom-innerHTML-HTML"><code>innerHTML</code> in HTML</span></td>
+     <td><span title="dom-document-write-XML"><code>document.write()</code> in XML</span></td>
     </tr>
     <tr>
-     <th>For documents that are <span>XML documents</span></th>
-     <td><span title="dom-document-write-XML"><code>document.write()</code> in XML</span></td>
+     <th><dfn title="dom-innerHTML"><code>innerHTML</code></dfn></th>
+     <td><span title="dom-innerHTML-HTML"><code>innerHTML</code> in HTML</span></td>
      <td><span title="dom-innerHTML-XML"><code>innerHTML</code> in XML</span></td>
     </tr>
+    <tr>
+     <th><dfn title="dom-outerHTML"><code>outerHTML</code></dfn></th>
+     <td><span title="dom-outerHTML-HTML"><code>outerHTML</code> in HTML</span></td>
+     <td><span title="dom-outerHTML-XML"><code>outerHTML</code> in XML</span></td>
+    </tr>
    </tbody>
   </table>
 
   <p>Regardless of the parsing mode, the <dfn
   title="dom-document-writeln"><code>document.writeln(...)</code></dfn>
   method must call the <code
   title="dom-document-write">document.write()</code> method with the
   same argument(s), plus an extra argument consisting of a string
   containing a single line feed character (U+000A).</p>
 
@@ -6844,34 +6850,28 @@ http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20HTML%3E%0
    </li>
 
    <li>
 
     <p>Finally, the method must return.</p>
 
    </li>
 
   </ol>
 
-  <p>In HTML, the <dfn
+  <hr>
+
+  <p>On getting, the <dfn
   title="dom-innerHTML-HTML"><code>innerHTML</code></dfn> DOM
-  attribute of all <code>HTMLElement</code> and
-  <code>HTMLDocument</code> nodes returns a serialization of the
-  node's children using the <span>HTML syntax</span><!-- XXX xref
-  -->. On setting, it replaces the node's children with new nodes that
-  result from parsing the given value. The formal definitions
-  follow.</p>
-
-  <p>On getting, the <code title="dom-innerHTML-HTML">innerHTML</code>
-  DOM attribute must return the result of running the <span>HTML
-  fragment serialization algorithm</span> on the node.</p>
-
-  <p>On setting, if the node is a document, the <code
+  attribute must return the result of running the <span>HTML fragment
+  serialization algorithm</span> on the node.</p>
+
+  <p>On setting, <strong>if the node is a document</strong>, the <code
   title="dom-innerHTML-HTML">innerHTML</code> DOM attribute must run
   the following algorithm:</p>
 
   <ol>
 
    <li>
 
     <p>If the document has an <span>active parser</span><!--XXX
     xref-->, then stop that parser, and throw away any pending content
     in the input stream. <span class="big-issue">what about if it
@@ -6972,59 +6972,124 @@ http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20HTML%3E%0
    <li>
 
     <p>Append all the <var title="">new children</var> nodes to the
     node whose <code title="dom-innerHTML-HTML">innerHTML</code>
     attribute is being set, preserving their order.</p>
 
    </li>
 
   </ol>
 
+  <hr>
+
+  <p>On getting, the <dfn
+  title="dom-outerHTML-HTML"><code>outerHTML</code></dfn> DOM
+  attribute must return the result of running the <span>HTML fragment
+  serialization algorithm</span> on a fictional node whose only child
+  is the node on which the attribute was invoked.</p>
+
+  <p>On setting, the <code title="dom-outerHTML-HTML">outerHTML</code>
+  DOM attribute must cause the following algorithm to run:</p>
+
+  <ol>
+
+   <li>
+
+    <p>Let <var title="">target</var> be the element whose <code
+    title="dom-innerHTML-HTML">outerHTML</code> attribute is being
+    set.</p>
+
+   </li>
+
+   <li>
+
+    <p>If <var title="">target</var> has no parent node, then abort
+    these steps. There would be no way to obtain a reference to the
+    nodes created even if the remaining steps were run.</p>
+
+   </li>
+
+   <li>
+
+    <p>If <var title="">target</var>'s parent node is a
+    <code>Document</code> object, throw a
+    <code>NO_MODIFICATION_ALLOWED_ERR</code> exception and abort these
+    steps.</p>
+
+   </li>
+
+   <li>
+
+    <p>Invoke the <span>HTML fragment parsing algorithm</span>, with
+    <var title="">target</var>'s parent element as the <var
+    title="">context</var> element and the string being assigned into
+    the <code title="dom-outerHTML-HTML">outerHTML</code> attribute as
+    the <var title="">input</var>. Let <var title="">new
+    children</var> be the result of this algorithm.</p>
+
+   </li>
+
+   <li>
+
+    <p>Let <var title="">target document</var> be the <code
+    title="">ownerDocument</code> of <var title="">target</var>.</p>
+
+   </li>
+
+   <li>
+
+    <p>Set the <code title="">ownerDocument</code> of all the nodes in
+    <var title="">new children</var> to the <var title="">target
+    document</var>.</p>
+
+   </li>
+
+   <li>
+
+    <p>Remove <var title="">target</var> from its parent node and
+    insert in its place all the <var title="">new children</var>
+    nodes, preserving their order.</p>
+
+   </li>
+
+  </ol>
+
+  <hr>
+
+  <p class="note">The <code
+  title="dom-innerHTML-HTML">innerHTML</code> attribute applies to
+  both <code>Element</code> nodes as well as <code>Document</code>
+  nodes. The <code title="dom-outerHTML-HTML">outerHTML</code>
+  attribute, on the other hand, only applies to <code>Element</code>
+  nodes.</p>
+
   <p class="note"><code>script</code> elements inserted using <code
-  title="dom-innerHTML-HTML">innerHTML</code> do not execute when they
+  title="dom-innerHTML-HTML">innerHTML</code> and <code
+  title="dom-outerHTML-HTML">outerHTML</code> do not execute when they
   are inserted.</p>
 
   <!-- XXX must make sure we spec that innerHTML causes mutation
   events to fire, but document.write() doesn't. (the latter is already
   req-stated in the parser section, btw) -->
 
   <!-- http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerhtml.asp -->
   <!-- http://lxr.mozilla.org/seamonkey/source/content/html/content/src/nsGenericHTMLElement.cpp#879
        note script execution disabled
        http://lxr.mozilla.org/seamonkey/source/content/base/src/nsContentUtils.cpp#3308
        http://trac.webkit.org/projects/webkit/browser/trunk/WebCore/html/HTMLElement.cpp#L295
        http://trac.webkit.org/projects/webkit/browser/trunk/WebCore/html/HTMLElement.cpp#L242
        http://trac.webkit.org/projects/webkit/browser/trunk/WebCore/html/HTMLTokenizer.cpp#L1742
    -->
 
 
   <h4>Dynamic markup insertion in XML</h4>
 
-  <p>In an XML context, the <dfn
-  title="dom-document-write-XML"><code>document.write()</code></dfn>
-  method must raise an <code>INVALID_ACCESS_ERR</code> exception.</p>
-
-<!--
-  For XHTML: content must be well-formed. Where does
-  it insert? Immediately after the script that called document.write()?</p>
-  how do we handle async scripts vs sync scripts?
-
-Consider:
-data:text/xml,<script xmlns="http://www.w3.org/1999/xhtml"><![CDATA[ document.write('<foo>Test</foo>'); ]]></script>
-data:text/xml,<script xmlns="http://www.w3.org/1999/xhtml"><![CDATA[ alert('test'); alert(document.write); try { document.write('<foo>Test</foo>'); alert(document.childNodes.length); } catch (e) { alert(e); } ]]></script>
-
--->
-
-  <p>On the other hand, however, the <dfn
-  title="dom-innerHTML-XML"><code>innerHTML</code></dfn> attribute is
-  indeed usable in an XML context.</p>
-
   <p>In an XML context, the <code
   title="dom-innerHTML-XML">innerHTML</code> DOM attribute on
   <code>HTMLElement</code>s must return a string in the form of an <a
   href="http://www.w3.org/TR/xml/#wf-entities">internal general parsed
   entity</a>, and on <code>HTMLDocument</code>s must return a string
   in the form of a <a
   href="http://www.w3.org/TR/xml/#sec-well-formed">document
   entity</a>. The string returned must be XML namespace-well-formed
   and must be an isomorphic serialization of all of that node's child
   nodes, in document order. User agents may adjust prefixes and
@@ -7183,20 +7248,32 @@ data:text/xml,<script xmlns="http://www.w3.org/1999/xhtml"><![CDATA[ alert('test
     attribute is being set, preserving their order.</p>
 
    </li>
 
   </ol>
 
   <p class="note"><code>script</code> elements inserted using <code
   title="dom-innerHTML-XML">innerHTML</code> do not execute when they
   are inserted.</p>
 
+  <p>In an XML context, the <dfn
+  title="dom-document-write-XML"><code>document.write()</code></dfn>
+  method, and the <dfn
+  title="dom-outerHTML-XML"><code>outerHTML</code></dfn> attribute on
+  both getting and setting, must raise an
+  <code>INVALID_ACCESS_ERR</code> exception.</p>
+
+<!--
+Where would document.write() insert?
+Consider: data:text/xml,<script xmlns="http://www.w3.org/1999/xhtml"><![CDATA[ document.write('<foo>Test</foo>'); ]]></script>
+-->
+
 
 
 
   <h2 id="semantics">The elements of HTML</h2>
 
   <h3>The root element</h3>
 
   <h4>The <dfn><code>html</code></dfn> element</h4>
 
   <dl class="element">
@@ -23442,26 +23519,26 @@ function AddCloud(data, x, y) { ... }</pre>
    </li>
 
    <li>
 
     <p>If the <code>script</code> element is <span>without
     script</span>, or if the <code>script</code> element was created
     by an <span>XML parser</span> that itself was created as part of
     the processing of the <code
     title="dom-innerHTML-XML">innerHTML</code> attribute's setter<!--
     no need to worry about the innerHTML-HTML case, as the HTML parser
-    handles that for us-->, or if the user agent does not
-    <span>support the scripting language</span> given by <var>the
-    script's type</var> for this <code>script</code> element, or if
-    the <code>script</code> element has its <span>"already
-    executed"</span> flag set, then the user agent must abort these
-    steps at this point. The script is not executed.</p>
+    handles that for us, and outerHTML-XML doesn't work-->, or if the
+    user agent does not <span>support the scripting language</span>
+    given by <var>the script's type</var> for this <code>script</code>
+    element, or if the <code>script</code> element has its
+    <span>"already executed"</span> flag set, then the user agent must
+    abort these steps at this point. The script is not executed.</p>
 
    </li>
 
    <li>
 
     <p>The user agent must set the element's <span>"already
     executed"</span> flag.</p>
 
    </li>
 
@@ -43222,28 +43299,28 @@ interface <dfn>MessageChannel</dfn> {
 
    <li>If <var title="">node</var> is a <code>head</code> element,
    then switch the <span>insertion mode</span> to "<span
    title="insertion mode: in body">in body</span>" ("<span
    title="insertion mode: in body">in body</span>"! <em> not "<span
    title="insertion mode: in head">in head</span>"</em>!) and abort
    these steps. (<span>fragment case</span>)</li> <!-- This is only
    here for now in case people think that the spec accidentally
    omitted it and try to "fix" it. Note that noscript-in-head is also
    handled this way. This is all intentional. The only thing it
-   doesn't handle is the scripting-enabled fragment parsing case for a
-   <head> element containing a <noscript> which itself contains
+   doesn't handle is the scripting-disabled fragment parsing case for
+   a <head> element containing a <noscript> which itself contains
    something other than a <link> or a <style> element; you'd expect
    that to break out of the <noscript> but it doesn't. This is an edge
    case that doesn't affect the spec, since the algorithm for fragment
-   parsing is only used for innerHTML, where we know scripting is
-   enabled. (XXX except maybe if innerHTML is set from another
-   browsing context on a document with designMode set?) -->
+   parsing is only used for innerHTML/outerHTML, where we know
+   scripting is enabled. (XXX except maybe if innerHTML is set from
+   another browsing context on a document with designMode set?) -->
 
    <li>If <var title="">node</var> is a <code>body</code> element,
    then switch the <span>insertion mode</span> to "<span
    title="insertion mode: in body">in body</span>" and abort these
    steps.</li>
 
    <li>If <var title="">node</var> is a <code>frameset</code> element,
    then switch the <span>insertion mode</span> to "<span
    title="insertion mode: in frameset">in frameset</span>" and abort
    these steps. (<span>fragment case</span>)</li>
@@ -45815,25 +45892,25 @@ interface <dfn>MessageChannel</dfn> {
 
     <p>If the parser was originally created for the <span>HTML
     fragment parsing algorithm</span>, then mark the
     <code>script</code> element as <span>"already executed"</span>,
     and skip the rest of the processing described for this token
     (including the part below where "<span title="pending external
     script">pending external scripts</span>" are
     executed). (<span>fragment case</span>)</p>
 
     <p class="note">Marking the <code>script</code> element as
-    "already executed" prevents it from executing when it is
-    inserted into the document a few paragraphs below. Thus,
-    scripts missing their end tags and scripts that were inserted
-    using <code title="dom-innerHTML-HTML">innerHTML</code> aren't
-    executed.</p>
+    "already executed" prevents it from executing when it is inserted
+    into the document a few paragraphs below. Thus, scripts missing
+    their end tags and scripts that were inserted using <code
+    title="dom-innerHTML-HTML">innerHTML</code>/<code
+    title="dom-outerHTML-HTML">outerHTML</code> aren't executed.</p>
 
     <p>Let the <var title="">old insertion point</var> have the
     same value as the current <span>insertion point</span>. Let
     the <span>insertion point</span> be just before the <span>next
     input character</span>.</p>
 
     <p>Append the new element to the <span>current node</span>.
     <span title="running a script">Special processing occurs when
     a <code>script</code> element is inserted into a
     document</span> that might cause some script to execute, which
@@ -48344,21 +48421,22 @@ interface <dfn>MessageChannel</dfn> {
     title="insertion mode: in body">in body</span>" <span>insertion
     mode</span>.</p>
    </dd>
 
    <dt>An end tag whose tag name is "html"</dt>
    <dd>
 
     <p>If the parser was originally created as part of the <span>HTML
     fragment parsing algorithm</span>, this is a <span>parse
     error</span>; ignore the token.  (<span>fragment case</span>)</p>
-    <!-- can only happen for <html>'s own innerHTML -->
+    <!-- can only happen for <html>'s own innerHTML or its children's
+    outerHTML -->
 
     <p>Otherwise, switch the <span>insertion mode</span> to "<span
     title="insertion mode: after after body">after after
     body</span>".</p>
 
    </dd>
 
    <dt>An end-of-file token</dt>
    <dd>
     <p><span>Stop parsing</span>.</p>
@@ -48955,21 +49033,21 @@ http://lxr.mozilla.org/seamonkey/search?string=nested
 
        <dd>
 
         <p>If one of the ancestors of <var title="">current node</var>
         is a <code>style</code>, <code>script</code>,
         <code>xmp</code>, <code>iframe</code>, <code>noembed</code>,
         <code>noframes</code>, <code>noscript</code>, or
         <code>plaintext</code> element, then append the value of <var
         title="">current node</var>'s <code title="">data</code> DOM
         attribute literally.</p> <!-- note about noscript: we're
-        assuming here that scripting is disabled. If this algorithm is
+        assuming here that scripting is enabled. If this algorithm is
         used with scripting disabled, this won't work right. XXX This
         might affect calling innerHTML on nodes in a document that is
         being designMode'd -->
 
         <p>Otherwise, append the value of <var title="">current
         node</var>'s <code title="">data</code> DOM attribute, <span
         title="escaping a string">escaped as described
         below</span>.</p>
 
        </dd>

|