Documentation of createHTMLDocument incorrect - No <!DOCTYPE html>

RESOLVED WORKSFORME

Status

()

Core
DOM: Core & HTML
RESOLVED WORKSFORME
7 months ago
7 months ago

People

(Reporter: Charles Bradshaw, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

7 months ago
User Agent: Mozilla/5.0 (X11; Fedora; Linux i686; rv:52.0) Gecko/20100101 Firefox/52.0
Build ID: 20170306104049

Steps to reproduce:

Run sample code from documentation page:
https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument, then  right click in iframe, select This Frame > Save Fame As

If the iframe PREVIOUSLY contained a correct doctype then <!DOCTYPE html> is output.


Actual results:

<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>New Document</title><script></script><style></style></head><body><p>This is a new paragraph.</p></body></html>


Expected results:

<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>New Document</title><script></script><style></style></head><body><p>This is a new paragraph.</p></body></html>
(Reporter)

Comment 1

7 months ago
Initial iframe tag: <iframe id="iframe" src="about:blank" scrolling="auto" contenteditable="true"></iframe>

Updated

7 months ago
Component: Untriaged → API: DOM
Product: Firefox → Developer Documentation
Version: 52 Branch → unspecified
(Reporter)

Comment 2

7 months ago
Workround - Insert the following before the createHTMLDocument.

      iframe.contentDocument.open(); 
      iframe.contentDocument.write("<!DOCTYPE html>\n");
      iframe.contentDocument.close();

iframe is the existing iframe element.
This appears to actually be a Firefox bug. According to the specification, step 3 when handling createHTMLDocument() is "Append a new doctype, with 'html' as its name and with its node document set to [the new document]".

Reassigning for the dev team to evaluate.
Component: API: DOM → DOM: Core & HTML
Product: Developer Documentation → Core
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4946 shows we correctly create a document with a doctype. The live example shows that if you create a document with a doctype, and then transfer only the root element (and not the doctype!) to another document (that never had a doctype), the other document doesn't magically gain a doctype.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 7 months ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.