From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/document/importnode/index.html | 111 ++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 files/ja/web/api/document/importnode/index.html (limited to 'files/ja/web/api/document/importnode/index.html') diff --git a/files/ja/web/api/document/importnode/index.html b/files/ja/web/api/document/importnode/index.html new file mode 100644 index 0000000000..3a6768769d --- /dev/null +++ b/files/ja/web/api/document/importnode/index.html @@ -0,0 +1,111 @@ +--- +title: Document.importNode() +slug: Web/API/Document/importNode +tags: + - API + - DOM + - Document + - Method + - Node + - Reference + - copy + - importNode +translation_of: Web/API/Document/importNode +--- +
{{APIRef("DOM")}}
+ +

{{domxref("Document")}} オブジェクトの importNode() メソッドは、後で現在の文書に挿入するために、他の文書から {{domxref("Node")}} または {{domxref("DocumentFragment")}} の複製を作成します。

+ +

インポートされたノードは、まだ文書ツリーには含まれません。これを含めるには、 {{domxref("Node.appendChild", "appendChild()")}} や {{domxref("Node.insertBefore", "insertBefore()")}} のような挿入メソッドを、現在の文書ツリーに存在するノードに対して呼び出す必要があります。

+ +

{{domxref("document.adoptNode()")}} とは異なり、元の文書から元のノードは削除されません。インポートされたノードは元のノードの複製です。

+ +

構文

+ +
const importedNode = document.importNode(externalNode [, deep]);
+
+ +

引数

+ +
+
externalNode
+
現在の文書にインポートする、外部の {{domxref("Node")}} または {{domxref("DocumentFragment")}} です。
+
deep {{optional_inline}}
+
論理値で、 externalNode の DOM サブツリー全体をインポートするかどうかを制御します。 +
    +
  • deeptrue に設定された場合、 externalNode およびその子孫全てが複製されます。
  • +
  • deepfalse に設定された場合、 externalNode のみがインポートされます — 新しいノードには子ノードはない状態になります。
  • +
+ +
+

中: DOM4 仕様書では、 deep 羽オプションの引数で、既定値は true でした。

+ +

最新の仕様書ではこの既定値が変更されました。新しい既定値は false になりました。

+ +

おすすめの方法: これは現在もオプションの引数ですが、常に deep 引数を渡すことが後方互換性および前方互換性には有用です。

+ +
    +
  • Gecko 28.0 {{geckoRelease(28)}} では、コンソールでこの引数を省略しないよう開発者に警告しています。
  • +
  • Gecko 29.0 {{geckoRelease(29)}}) 以降、深いクローンではなく浅いクローンが既定値になっています。
  • +
+
+
+
+ +

返値

+ +

インポートする側の文書のスコープにコピーされた importedNode です。

+ +
+

注: importedNode's {{domxref("Node.parentNode")}} は null になります。まだ文書ツリーに挿入されていないからです。

+
+ +

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

+ +

{{page("/ja/docs/Web/API/Document/adoptNode", "Notes")}}

+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName("DOM WHATWG", "#dom-document-importnode", "document.importNode()")}}{{Spec2("DOM WHATWG")}}
{{SpecName("DOM2 Core", "core.html#Core-Document-importNode", "document.importNode()")}}{{Spec2("DOM2 Core")}}初回定義
+ +

ブラウザーの互換性

+ + + +

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

+ +

関連情報

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