--- title: element.onbeforescriptexecute slug: Web/API/Document/beforescriptexecute_event tags: - DOM translation_of: Web/API/Document/onbeforescriptexecute original_slug: Web/API/Document/onbeforescriptexecute ---
HTML 文書内で宣言された {{HTMLElement("script")}} 要素内のコードの実行開始直前に発生するイベントをハンドリングします。appendChild() などを用いるなどして動的に追加された script 要素ではこのイベントは発生しません。
document.onbeforescriptexecute = funcRef;
target 属性は実行される script 要素に設定されます。// ※ logMessage 関数は定義済みとする
function starting(e) {
logMessage("スクリプト実行開始(ID:" + e.target.id + ")");
}
document.addEventListener("beforescriptexecute", starting, true);