[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/API/DOMImplementation/createHTMLDocument [Back]  [Original]

DOMImplementation: createHTMLDocument() - Web API | MDN

MDN Web Docs

View in English Always switch to English

DOMImplementation: createHTMLDocument()

Baseline

20157

DOMImplementation.createHTMLDocument() HTML (Document)

js
createHTMLDocument()
createHTMLDocument(title)

title

HTML

HTML Document

HTML <iframe>

HTML

html
<body>
  <p>
    Click <a href="javascript:makeDocument()">here</a> to create a new document
    and insert it below.
  </p>
  <iframe id="theFrame" src="about:blank" />
</body>

JavaScript makeDocument()

js
function makeDocument() {
  let frame = document.getElementById("theFrame");

  let doc = document.implementation.createHTMLDocument("New Document");
  let p = doc.createElement("p");
  p.textContent = "This is a new paragraph.";

  try {
    doc.body.appendChild(p);
  } catch (e) {
    console.log(e);
  }

  // Copy the new HTML document into the frame

  let destDocument = frame.contentDocument;
  let srcNode = doc.documentElement;
  let newNode = destDocument.importNode(srcNode, true);

  destDocument.replaceChild(newNode, destDocument.documentElement);
}

412 HTML 4 createHTMLDocument() <title> "New Document" HTML 5 6 812

16 contentDocument 2 20

HTML

html
<!doctype html>
<html lang="en-US">
  <head>
    <meta charset="UTF-8" />
    <title>title</title>
  </head>
  <body>
    
  </body>
</html>

DOM
# ref-for-dom-domimplementation-createhtmldocument


Web Proxy Viewer  |  New URL  |  Original Page