Import the first <h1> element from an iframe (another document):
const frame = document.getElementsById("myFrame");
const h1 = frame.contentWindow.document.getElementsByTagName("H1")[0];
const node = document.importNode(h1, true);
Try it Yourself »
The importNode()
method imports a node from another document.
With the second parameter set to true
, child nodes will also be imported.
The imported node is not removed from the original document.
The imported node is a copy of the original.
document.importNode(
node,
deep)
Parameter | Description |
node | Required. A node from another document. Can be type of node. |
deep | Required.false : only the node itself is imported.true : child nodes (descendants) are also imported. |
Type | Description |
Node | The imported node. |
document.importNode()
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!