Document: currentScript プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Document.currentScript
プロパティは、現在処理中で、 JavaScript モジュールではないスクリプトの <script>
要素を返します。(モジュールの場合は代わりに import.meta
を使用してください。)
重要なことですが、スクリプト内のコードがコールバックまたはイベントハンドラーとして呼び出されている場合は、 <script>
要素を参照しないことに注意してください。初期化時に処理されている要素のみを参照します。
値
HTMLScriptElement
または null です。
例
次の例では、スクリプトが非同期で実行されているかどうかをチェックしています。
js
if (document.currentScript.async) {
console.log("非同期で実行中");
} else {
console.log("同期で実行中");
}
仕様書
Specification |
---|
HTML # dom-document-currentscript-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
currentScript |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.