--- title: Document.currentScript slug: Web/API/Document/currentScript translation_of: Web/API/Document/currentScript ---
Возвращает элемент {{HTMLElement("script")}}, который выполняется в данный момент.
var curScriptElement = document.currentScript;
Этот пример проверяет, выполняется ли текущий скрипт асинхронно:
if (document.currentScript.async) { console.log("Executing asynchronously"); } else { console.log("Executing synchronously"); }
Важно заметить, что элемент {{HTMLElement("script")}} не будет соответствовать текущему, если он выполняется внутри callback'a или event handler'a; он будет соответствовать элементу только при начальном выполнении скрипта.
Specification | Status | Comment |
---|---|---|
{{SpecName("HTML WHATWG", "dom.html#dom-document-currentscript", "Document.currentScript")}} | {{Spec2("HTML WHATWG")}} | Initial definition |
{{Compat("api.Document.currentScript")}}