读取位于index.html的文件

Read file located up to index.html

本文关键字:文件 html index 读取      更新时间:2023-09-26

我是JavaScript新手。

我的index.html使用JavaScript读取文件。如果文件位于与index.html相同的目录或相对于它,我可以成功读取它。但是当文件位于index.html (../../myfile)时,JavaScript无法访问它。有可能用标准JavaScript读取文件吗?

也许这有助于读取本地文件:

function readFile(data, elem, file, index) {
     if (!file)
         return;
     var reader = new FileReader();
     reader.onloadend = readFileLoadEnd(data, elem, file, index);
     reader.readAsDataURL(file);
 }