Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since июль 2015 г..
Свойство Document.currentScript возвращает элемент <script>, код которого в данный момент выполняется и не является модулем JavaScript. Для модулей необходимо использовать import.meta.
Важно отметить, что ссылка на элемент <script> будет присутствовать только во время первоначального исполнения скрипта. Иными словами, если код в скрипте вызывается как функция обратного вызова или обработчик события, то Document.currentScript будет равен null.
HTMLScriptElement или null.
Этот пример проверяет, выполняется ли скрипт асинхронно:
| HTML # dom-document-currentscript-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2 дек. 2024 г. by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.