How to get current file path in javascript

can I get the full path to my html page via javascript, for example, the page "My index" is in

d:/somefolder/anotherfolder/index.html 

so that I can get this way

thanks

+6
source share
3 answers

You can only access the current file path relative to your host URL, you cannot access the folder path of this file.

This is not allowed in JavaScript due to security concerns. If it was allowed, malicious scripts can easily read the internal folder structures of your server, which is bad.

+6
source

This is not possible on the local computer, however you can use:

 document.location.href; 

to get the url where your file is located

+2
source

no, you cannot allow the browser to not allow javascript to access the file path due to security reasons

0
source

Source: https://habr.com/ru/post/953148/


All Articles