Возвращает элемент <script>
, который выполняется в данный момент.
Синтаксис
var curScriptElement = document.currentScript;
Пример
Этот пример проверяет, выполняется ли текущий скрипт асинхронно:
if (document.currentScript.async) {
console.log("Executing asynchronously");
} else {
console.log("Executing synchronously");
}
Notes
Важно заметить, что элемент <script>
не будет соответствовать текущему, если он выполняется внутри callback'a или event handler'a; он будет соответствовать элементу только при начальном выполнении скрипта.
Спецификации
Specification | Status | Comment |
---|---|---|
HTML Living Standard Определение 'Document.currentScript' в этой спецификации. |
Живой стандарт | Initial definition |
Совместимость
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 29.0 | (Да) | 4.0 (2.0) | Нет | 16 | 8 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 4.4 | (Да) | (Да) | ? | ? | 8 |