如何在javascript中获取当前文件路径

时间:2021-03-02 16:01:38

can i get the full path of my html page through javascript eg My Index page is at

我可以通过javascript获取我的html页面的完整路径,例如我的索引页面是

         d:/somefolder/anotherfolder/index.html

so can i get this path

我也可以走这条路

Thanks

3 个解决方案

#1


6  

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

您只能访问相对于主机URL的当前文件路径,无法访问该文件的文件夹路径。

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.

由于安全原因,这在JavaScript中受到限制。如果允许,恶意脚本可以轻松读取服务器的内部文件夹结构,这很糟糕。

#2


2  

On a Local Machine it is not possible, however you could use:

在本地计算机上,它是不可能的,但您可以使用:

document.location.href;

to get the URL, where your file is hosted

获取托管文件的URL

#3


0  

no you can't browser don't allow javascript to access the file paths due to security reasons

不,你不能浏览器不允许javascript访问文件路径由于安全原因

#1


6  

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

您只能访问相对于主机URL的当前文件路径,无法访问该文件的文件夹路径。

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.

由于安全原因,这在JavaScript中受到限制。如果允许,恶意脚本可以轻松读取服务器的内部文件夹结构,这很糟糕。

#2


2  

On a Local Machine it is not possible, however you could use:

在本地计算机上,它是不可能的,但您可以使用:

document.location.href;

to get the URL, where your file is hosted

获取托管文件的URL

#3


0  

no you can't browser don't allow javascript to access the file paths due to security reasons

不,你不能浏览器不允许javascript访问文件路径由于安全原因