Closed Bug 1171039 Opened 10 years ago Closed 10 years ago

Creating a new HTMLDocument and using it's open/write()/close methods is a no-op

Categories

(Core :: DOM: Core & HTML, defect)

38 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: nikdunn1979, Unassigned, NeedInfo)

Details

(Keywords: testcase)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36 Steps to reproduce: Created a test page: <!doctype html> <html> <head> <script src="bower_components/jquery/dist/jquery.js"></script> <script> function bar() { var html = document.documentElement.outerHTML; var newDoc = document.implementation.createHTMLDocument(''); newDoc.open(); newDoc.write(html); newDoc.close(); debugger; } </script> </head> <body> <div id="main" class="m-scene" onclick="bar();">Foo</div> </body> </html> Actual results: newDoc.body has no child nodes. Works in other browsers. Expected results: newDoc.body should have had child nodes.
The bug also exists with very simple html fragments like: "<div>Foo</div>"
I would love to see a possible workaround, if possible, too.
Do you know if this used to work in earlier versions of Firefox?
Status: UNCONFIRMED → NEW
Component: Untriaged → DOM: Core & HTML
Ever confirmed: true
Flags: needinfo?(nikdunn1979)
Keywords: testcase
Product: Firefox → Core
Summary: HTMLDocument.write() is broken in Firefox 38.0 → Creating a new HTMLDocument and using it's write() method with the outerHTML of another document generates an empty body (body contents of original document are ignored)
Seems like this didn't work in at least Firefox 28, so if it did work it's been broken for a long time.
Summary: Creating a new HTMLDocument and using it's write() method with the outerHTML of another document generates an empty body (body contents of original document are ignored) → Creating a new HTMLDocument and using it's open/write()/close methods is a no-op
Per spec, for document.open at https://html.spec.whatwg.org/multipage/webappapis.html#dom-document-open step 2 is: If the Document object is not an active document, then abort these steps. The document in this case is not an active document, so document.open() is a no-op. Then you do the document.write, which lands at https://html.spec.whatwg.org/multipage/webappapis.html#document.write%28%29 and has the same step 2. So document.write is a no-op on this case as well.
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.