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/currentscript/index.html | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 files/ja/web/api/document/currentscript/index.html (limited to 'files/ja/web/api/document/currentscript/index.html') diff --git a/files/ja/web/api/document/currentscript/index.html b/files/ja/web/api/document/currentscript/index.html new file mode 100644 index 0000000000..0a7f43faee --- /dev/null +++ b/files/ja/web/api/document/currentscript/index.html @@ -0,0 +1,68 @@ +--- +title: Document.currentScript +slug: Web/API/Document/currentScript +tags: + - API + - DOM + - Document + - Property + - Reference + - プロパティ +translation_of: Web/API/Document/currentScript +--- +

{{APIRef("DOM")}}

+ +

Document.currentScript プロパティは、現在処理中で、 JavaScript モジュールではないスクリプトの {{HTMLElement("script")}} 要素を返します。 (モジュールの場合は代わりに {{JSxRef("Statements/import%2Emeta", "import.meta")}} を使用してください。

+ +

重要なことですが、スクリプト内のコードがコールバックまたはイベントハンドラーとして呼び出されている場合は、 {{HTMLElement("script")}} 要素を参照しないことに注意してください。初期化時に処理されている要素のみを参照します。

+ +

構文

+ +
var curScriptElement = document.currentScript;
+
+ +

+ +

次の例では、スクリプトが非同期で実行されているかどうかをチェックしています。

+ +
if (document.currentScript.async) {
+  console.log("非同期で実行中");
+} else {
+  console.log("同期で実行中");
+}
+ +

実際の表示を確認

+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName("HTML WHATWG", "dom.html#dom-document-currentscript", "Document.currentScript")}}{{Spec2("HTML WHATWG")}}初回定義
+ +

ブラウザーの互換性

+ + + +
{{Compat("api.Document.currentScript")}}
+ +

関連情報

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