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/adoptnode/index.html | 96 ++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 files/ja/web/api/document/adoptnode/index.html (limited to 'files/ja/web/api/document/adoptnode') diff --git a/files/ja/web/api/document/adoptnode/index.html b/files/ja/web/api/document/adoptnode/index.html new file mode 100644 index 0000000000..a43521e7ce --- /dev/null +++ b/files/ja/web/api/document/adoptnode/index.html @@ -0,0 +1,96 @@ +--- +title: Document.adoptNode() +slug: Web/API/Document/adoptNode +tags: + - API + - DOM + - DOM Reference + - Method + - NeedsExample + - NeedsSpecTable + - NeedsUpdate + - Reference +translation_of: Web/API/Document/adoptNode +--- +
{{ ApiRef("DOM") }}
+ +

Document.adoptNode() は、{{Glossary("node/dom", "ノード")}}を他の{{domxref("Document", "文書", "", "1")}}からメソッドの文書へ移動します。取り込まれたノードおよびそのサブツリーは (もしあれば) 元の文書から削除され、 {{domxref("Node.ownerDocument", "ownerDocument")}} が現在の文書に変更されます。その後、ノードを現在の文書に挿入することができます。

+ +

構文

+ +
const importedNode = document.adoptNode(externalNode);
+
+ +

引数

+ +
+
externalNode
+
他の文書から取り込まれるノードです。
+
+ +

返値

+ +

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

+ +

このメソッドを呼び出した後、 importedNode および externalNode は同じオブジェクトになります。

+ +
+

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

+
+ +

+ +
const iframe = document.querySelector('iframe');
+const iframeImages = iframe.contentDocument.querySelectorAll('img');
+const newParent = document.getElementById('images');
+
+iframeImages.forEach(function(imgEl) {
+  newParent.appendChild(document.adoptNode(imgEl));
+});
+
+ +

+ +

外部の文書から取り込まれるノードは、現在の文書に挿入する前に、次のいずれかを実行してください。

+ + + +
+

ベストプラクティス: Firefox は現在はこの規則を強制しませんが、将来の互換性を向上するためにこの規則に従うことを強くお勧めします。

+
+ +

{{domXref("Node.ownerDocument")}} の問題についての詳細は、 W3C DOM FAQ を参照してください。

+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('DOM WHATWG', '#dom-document-adoptnode', 'document.adoptNode')}}{{Spec2('DOM WHATWG')}}
+ +

ブラウザーの互換性

+ + + +

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

+ +

関連情報

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