can i get the full path of my html page through javascript eg My Index page is at
d:/somefolder/anotherfolder/index.html
so can i get this path
Thanks
In Node. js, there are two built-in ways to get the current directory. You can either use the __dirname variable or the process. cwd() method to get the current folder.
We can get the path of the present script in node. js by using __dirname and __filename module scope variables. __dirname: It returns the directory name of the current module in which the current script is located.
The proper method would be ./filename. ext . ../ addresses the path up one level from the current folder. If you were in the path /cheese/crackers/yummy.
You can only access your current file path relative to your host URL, you cannot access the folder path of that file.
This is restricted in JavaScript due to security reasons. If that was allowed, malicious scripts could easily read your server's internal folder structures, which is bad.
On a Local Machine it is not possible, however you could use:
document.location.href;
to get the URL, where your file is hosted
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With