是否有可能在未提供服务的页面上使用JS / HTML5 FileReader加载文件? [英] Is it possible to load a file with JS/HTML5 FileReader on non served page?
问题描述
我想在HTML5 / JS中创建一个简单的游戏,我不希望用户运行任何网络服务器或必须连接到网站。 (只是一个HTML页面)
但它看起来像FileReader只能用于文件类型输入。
是否有可能只有两个文件:index.html和foo.txt并排,并从index.html读取foo.txt,如下所示:
//没有输入需要,我知道我想读取
var my_file = new File(foo.txt);
var reader = new FileReader();
alert(reader.readAstext(my_file,UTF-8));
任何想法?
我相信这是你的答案:如何使用Javascript打开本地磁盘文件?
总之,您看起来像这样:
< input type =fileid =filesname =file/>
HTML5允许您加载本地存储在计算机上的文件,但无法选择它。用户必须选择他/她想要加载的文件。
想象一下,当开发者(或者说更好的口语,黑客)会可以访问每个人的本地数据......I want to create a simple game in HTML5/JS and I don't want the user to run any webserver or to have to connect to a website. (just an HTML page)
But it looks like FileReader can only be used on files type inputs.
Is it possible to have only two files : index.html and foo.txt side by side and to read foo.txt from index.html with something like :
// No input needed, I know waht I want to read
var my_file = new File("foo.txt");
var reader = new FileReader();
alert( reader.readAstext( my_file, "UTF-8" ) );
Any idea ?
I believe that this is your answer: How to open a local disk file with Javascript?
In short, you are looking something like this:
<input type="file" id="files" name="file" />
HTML5 allows you to load files which are stored locally on computer, but you cannot select it. User must select file which he/she wants to be loaded.
Just imagine what would happen when developers (or better spoken, hackers) would have access to everyones local data...
这篇关于是否有可能在未提供服务的页面上使用JS / HTML5 FileReader加载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!