HTML 本地文件访问

发布于 2024-11-10 03:23:28 字数 274 浏览 1 评论 0原文

我想访问直接目录中的本地文件

根据我的理解,您通常必须执行类似

file://path/to/file/document.html

需要完整路径的操作,但我想做类似的操作

file://./document.html

,其中 ./ 代表当前目录引用,这样我就不必知道目录路径,也不必对其做出任何假设。

html 文件路径是否有类似的技巧?

I would like to access a local file in the immediate directory

From my understanding, you'd usually have to do something like

file://path/to/file/document.html

which requires the full path, but I would like to do something like

file://./document.html

instead, where ./ represents the current directory reference, so that I do not have to know the directory path nor make any assumptions about it.

is there any trickery like that possible with html file paths?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月打碎记忆 2024-11-17 03:23:28

使用:

document.html

如果没有指定协议,也没有目录 /,浏览器应该从当前页面所在的同一目录/文件夹请求资源。

Use:

document.html

With no protocol specified, and no / for directories, the browser should request the asset from the same directory/folder that the current page is at.

南冥有猫 2024-11-17 03:23:28

如果它在本地运行(从该目录),只需使用 ./ 而不使用 file://

If it's running locally (from that directory), just use ./ without the file://.

闻呓 2024-11-17 03:23:28

尝试http://www.nt22.com/html_tutorials/022_html_path.html

使用页面 .html 和 ./page.html 的工作原理相同。

../ 进入下层目录

root/www/page.html

如果您在 root/stuff/hi.html 中,您可以通过执行以下操作转到“www”目录
../www/page.html

try this http://www.nt22.com/html_tutorials/022_html_path.html

using page.html and ./page.html works the same.

../ goes to a lower directory
i.e.

root/www/page.html

if you are in root/stuff/hi.html you can go to the 'www' directory by doing
../www/page.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文