-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
As it stands, the spec defines that document.open and document.write should be a no-op for a non-active document. See http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#dom-document-write:
If document is not an active document, then return.
However, document.open/write is a convenient (and essentially the only) way to incrementally stream-parse DOM. For instance:
var parser = document.implementation.createHTMLDocument('');
parser.open();
parser.write('<html><body>...');
parser.close();
Despite the spec, all major browsers except Firefox support this. See https://bugzilla.mozilla.org/show_bug.cgi?id=867102
Alternatives to using this API would be either parse the whole DOM in one go using DOMParser or, what most often done on Firefox as a workaround, to parse via a hidden iframe. IMHO both alternatives are significantly worse than expanding the spec to what most of browsers already do.