Document.scripts
Document インターフェイスの scripts プロパティは、文書中の <script> 要素のリストを返します。返されるオブジェクトは単一の HTMLCollection オブジェクトです。
構文
var scriptList = document.scripts;
値
HTMLCollection です。これを使用して、リスト中のすべての要素を配列のように取得することができます。
例
ページ内の <script> 要素の存在を確認する例を以下に示します。
js
let scripts = document.scripts;
if (scripts.length) {
alert("このページには script 要素があります。");
}
仕様書
| Specification |
|---|
| HTML Standard # dom-document-scripts-dev |
ブラウザーの互換性
BCD tables only load in the browser