From 1109132f09d75da9a28b649c7677bb6ce07c40c0 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:45 -0500 Subject: initial commit --- files/es/web/api/document/importnode/index.html | 84 +++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 files/es/web/api/document/importnode/index.html (limited to 'files/es/web/api/document/importnode') diff --git a/files/es/web/api/document/importnode/index.html b/files/es/web/api/document/importnode/index.html new file mode 100644 index 0000000000..ea34cd33be --- /dev/null +++ b/files/es/web/api/document/importnode/index.html @@ -0,0 +1,84 @@ +--- +title: Document.importNode() +slug: Web/API/Document/importNode +translation_of: Web/API/Document/importNode +--- +

{{APIRef("DOM")}}

+ +

Crea una copia de un nodo desde un documento externo para ser insertado en el documento actual.

+ +

Sintaxis

+ +
var node = document.importNode(externalNode, deep);
+
+ +
+
node
+
El nuevo nodo importado al documento actual. El parentNode del nuevo nodo es null, ya que aun no ha sido insertado en el arbol del documento.
+
externalNode
+
El nodo externo a ser importado
+
deep
+
Un booleano que indica si los descendientes del nodo deben ser importados también.
+
+ +
+

Nota: En la especificación DOM4 (tal y como se ha implementado en Gecko 13.0 {{geckoRelease(13)}}), deep es un argumento opcional. En el caso de ser omitido, adopta el valor de true, por lo que se hace una deep copy por defecto. Para realizar una copia superficial (shallow copy), deep debe ser false.

+ +

Este comportamiento ha cambiado en la ultima especificación, por lo que si se omite el parámetro deep, éste adopta el valor false. Aunque aún es opcional, debería ser siempre provisto por razones de compatibilidad. Con Gecko 28.0 {{geckoRelease(28)}}, la consola advertia a los desarrolladores de no omitir el argumento. Empezando con Gecko 29.0 {{geckoRelease(29)}}), se realiza una copia superficial (shallow copy) por defecto.

+
+ +

Ejemplo

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

Notas

+ +

El nodo original no se borra del documento. El nodo importado es un clon del original.

+ +

 

+ +

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.

+ +

 

+ +

Especificaciones

+ + + + + + + + + + + + + + + + + + + +
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
+ +

Compatibilidad navegadores

+ +
+ + +

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

+
+ +

See also

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