Let type be the value of the first argument, if
there is one, or "text/html" otherwise.
Let replace be true if there is a second argument
and it has the value "replace", and
false otherwise.
If the document has an active parser
that isn't a script-created parser, and
the insertion point associated with that
parser's input stream is not undefined (that is,
it does point to somewhere in the input stream), then the
method does nothing. Abort these steps and return the
Document object on which the method was invoked.
This basically causes
onbeforeunload, onunload, reset timers, empty event
queue, kill any pending transactions, XMLHttpRequests, etc
If the document has an active parser,
then stop that parser, and throw away any pending content in the input
stream. what about if it doesn't, because it's
either like a text/plain, or Atom, or PDF, or XHTML, or image document,
or something?
Remove all child nodes of the document.
Create a new HTML parser and associate it with
the document. This is a script-created
parser (meaning that it can be closed by the
Mark the document as being an HTML document (it might already be so-marked).
If type does not have the value
"text/html", then act as if the
tokeniser had emitted a HTML parser's tokenisation stage's content model flag to PLAINTEXT.
If replace is false, then:Remove all the entries in the browsing
context's session history after the current entry in its Document's
Remove any earlier entries that share the same Document
Add a new entry just before the last entry that is associated with
the text that was parsed by the previous parser associated with the
Document object, as well as the state of the document at
the start of these steps. (This allows the user to step backwards in
the session history to see the page before it was blown away by the
Finally, set the insertion point to point at
just before the end of the input stream (which at
this point will be empty).
Return the Document on which the method was invoked.