Closed Bug 1346524 Opened 7 years ago Closed 7 years ago

Documentation of createHTMLDocument incorrect - No <!DOCTYPE html>

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: charles.bradshaw, Unassigned)

Details

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>
Initial iframe tag: <iframe id="iframe" src="about:blank" scrolling="auto" contenteditable="true"></iframe>
Component: Untriaged → API: DOM
Product: Firefox → Developer Documentation
Version: 52 Branch → unspecified
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
Closed: 7 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.