Sometimes, we want to get the file path of the currently executing JavaScript code.
In this article, we’ll look at how to get the file path of the currently executing JavaScript code.
How to get the file path of the currently executing JavaScript code?
To get the file path of the currently executing JavaScript code, we can use the document.currentScript
property.
For instance, we write
const script = document.currentScript;
const fullUrl = script.src;
to get the currently running script with document.currentScript
.
Then we get the path of the script with script.src
.
Conclusion
To get the file path of the currently executing JavaScript code, we can use the document.currentScript
property.