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/open/index.html | 114 ++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 files/ja/web/api/document/open/index.html (limited to 'files/ja/web/api/document/open/index.html') diff --git a/files/ja/web/api/document/open/index.html b/files/ja/web/api/document/open/index.html new file mode 100644 index 0000000000..1b9da4d82f --- /dev/null +++ b/files/ja/web/api/document/open/index.html @@ -0,0 +1,114 @@ +--- +title: Document.open() +slug: Web/API/Document/open +tags: + - API + - DOM + - Document + - Method + - Reference + - open + - メソッド +translation_of: Web/API/Document/open +--- +
{{APIRef("DOM")}}
+ +

Document.open() メソッドは、{{domxref("Document.write", "書き込み", "", "1")}}のために文書を開きます。

+ +

これはいくらかの副作用を招きます。例を挙げます。

+ + + +

構文

+ +
document.open();
+
+ +

引数

+ +

なし。

+ +

返値

+ +

Document オブジェクトインスタンスです。

+ +

+ +

以下の簡単なコードは、文書を開き、その内容をいくつかの異なる HTML の断片に置き換えてから、再び閉じます。

+ +
document.open();
+document.write("<p>Hello world!</p>");
+document.write("<p>I am a fish</p>");
+document.write("<p>The number is 42</p>");
+document.close();
+
+ +

+ +

ページが読み込まれたあとで {{domxref("document.write()")}} が呼び出されると、自動的に document.open() が呼び出されます。

+ +

Firefox や Internet Explorer では何年も前から、すべてのノードの削除に加えて、 JavaScript の変数なども追加で消去していました。今はそうではありません。document non-spec'ed parameters to document.open

+ +

Gecko 固有のメモ

+ +

Gecko 1.9 以降、このメソッドは他のプロパティと同一オリジンポリシーが同じになるようになり、文書のオリジンを変更しようとした場合に動作しません。

+ +

Gecko 1.9.2 以降、 document.open()プリンシパルをスタックからフェッチするのではなく、 URI を使用する文書のプリンシパルを使用します。その結果、 wrappedJSObject を使用しても、 {{domxref("document.write()")}} を{{Glossary("chrome", "クローム")}}からの信頼できない文書に呼び出すことはできません。考え方についてはセキュリティチェックの基本を参照してください。

+ +

引数3つの document.open()

+ +

あまり知られていませんが、あまり使われていない引数3つ版の document.open() があり、これは {{domxref("Window.open()")}} のエイリアスです (詳細はそのページを参照してください)。

+ +

この呼び出しは、例えば github.com を新しいウィンドウで開き、オープナーは null に設定してみます。

+ +
document.open('https://www.github.com','', 'noopener=true')
+ +

引数2つの document.open()

+ +

ブラウザーは以下の形で、引数2つの document.open() に対応してきました。

+ +
document.open(type, replace)
+ +

type は書き込もうとしているデータの MIME タイプ (text/html など) を指定し、 replace が設定されていれば (すなわち "replace" の文字列)、新しい文書の履歴エントリが書き込まれている文書の現在の履歴エントリを置き換えることを指定していました。

+ +

この形式は現在では廃止されています。エラーは発生せず、代わりに document.open() に転送されます (つまり、引数なしで実行した場合と同等です)。 履歴の置換動作は常に行われるようになりました。

+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName("HTML WHATWG", "#dom-document-open", "document.open()")}}{{Spec2("HTML WHATWG")}}
{{SpecName("DOM2 HTML", "html.html#ID-72161170", "document.open()")}}{{Spec2("DOM2 HTML")}}
+ +

ブラウザーの互換性

+ + + +

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

+ +

See also

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