--- title: element.onbeforescriptexecute slug: Web/API/Document/beforescriptexecute_event tags: - DOM - onbeforescriptexecute translation_of: Web/API/Document/onbeforescriptexecute original_slug: Web/API/Document/onbeforescriptexecute ---
当HTML文档中的<script>标签内的代码将要执行时触发该事件,如果这个script标签是用appendChild()等方法动态添加上去的,则不会触发该事件.
document.onbeforescriptexecute = funcRef;
当beforescriptexecute事件触发时,funcRef函数就会被调用. 传入参数event的target属性指向触发该事件的那个script元素.
function starting(e) {
logMessage("Starting script with ID: " + e.target.id);
}
document.addEventListener("beforescriptexecute", starting, true);