简体   繁体   English

HTML 本地文件访问

[英]HTML local file access

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? html 文件路径是否有类似的诡计?

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

using page.html and./page.html works the same.使用 page.html 和 ./page.html 的工作原理相同。

../ goes to a lower directory ie ../ 转到较低的目录,即

root/www/page.html根/www/page.html

if you are in root/stuff/hi.html you can go to the 'www' directory by doing../www/page.html如果您在 root/stuff/hi.html 中,您可以通过执行 go 到“www”目录../www/page.html

If it's running locally (from that directory), just use ./ without the file:// .如果它在本地运行(从该目录),只需使用./而不使用file://

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.如果没有指定协议,也没有/目录,浏览器应该从当前页面所在的同一目录/文件夹中请求资产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM