From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/ru/web/api/document/importnode/index.html | 91 +++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 files/ru/web/api/document/importnode/index.html (limited to 'files/ru/web/api/document/importnode') diff --git a/files/ru/web/api/document/importnode/index.html b/files/ru/web/api/document/importnode/index.html new file mode 100644 index 0000000000..11cfa529ad --- /dev/null +++ b/files/ru/web/api/document/importnode/index.html @@ -0,0 +1,91 @@ +--- +title: Document.importNode() +slug: Web/API/Document/importNode +translation_of: Web/API/Document/importNode +--- +
{{APIRef("DOM")}}
+ +

Метод importNode()объекта {{domxref("Document")}} создает копию {{domxref("Node")}} или {{domxref("DocumentFragment")}} из другого документа, для последующей вставки в текущий документ.

+ +

Импортированный узел пока еще не включен в дерево документов. Чтобы добавить его, вам необходимо вызвать один из методов вставки, например,  {{domxref("Node.appendChild", "appendChild()")}} или {{domxref("Node.insertBefore", "insertBefore()")}} с узлом, который находится в дереве документов.

+ +

В отличие от {{domxref("document.adoptNode()")}}, исходный узел не удаляется из исходного документа. Импортированный узел является клоном оригинала.

+ +

Синтаксис

+ +
var node = document.importNode(externalNode, deep);
+
+ +
+
node
+
Копируемый узел из области видимости импортируемого документа . Свойство {{domxref("Node.parentNode")}} узла = null, до тех пор, пока он не будет вставлен в дерево документа.
+
externalNode
+
Внешний Node или DocumentFragment, который импортируется в настоящий документ.
+
deep
+
Булеан, контролирующий, необходимо ли импортировать всё DOM поддерево узла  externalNode. +
    +
  • Если deep установлен в true, узел externalNode и все его потомки будут скопированы.
  • +
  • Если deep установлен в false, ипморируется только externalNode  — новый узел не будет содержать потомков.
  • +
+
+
+ +
+

Note: In the DOM4 specification, deep was an optional argument with a default value of true.

+ +

This default has changed in the latest spec — the new default value is false. Though it's still an optional argument, you should always provide the deep argument for backward and forward compatibility. With Gecko 28.0 {{geckoRelease(28)}}, the console warns developers not to omit the argument. Starting with Gecko 29.0 {{geckoRelease(29)}}), a shallow clone is defaulted instead of a deep clone.

+
+ +

Example

+ +
var iframe = document.querySelector("iframe");
+var oldNode = iframe.contentWindow.document.getElementById("myNode");
+var newNode = document.importNode(oldNode, true);
+document.getElementById("container").appendChild(newNode);
+
+ +

Notes

+ + + +

Nodes from external documents should be cloned using document.importNode() (or adopted using document.adoptNode()) before they can be inserted into the current document. For more on the Node.ownerDocument issues, see the W3C DOM FAQ.

+ +

Firefox doesn't currently enforce this rule (it did for a while during the development of Firefox 3, but too many sites break when this rule is enforced). We encourage Web developers to fix their code to follow this rule for improved future compatibility.

+ + + +

Specifications

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("DOM WHATWG", "#dom-document-importnode", "document.importNode()")}}{{Spec2("DOM WHATWG")}}
{{SpecName("DOM2 Core", "core.html#Core-Document-importNode", "document.importNode()")}}{{Spec2("DOM2 Core")}}Initial definition
+ +

Browser compatibility

+ + + +

{{Compat("api.Document.importNode")}}

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf