opening any arbitrary file on disk using HTML File API

杀马特。学长 韩版系。学妹 提交于 2019-12-25 18:42:56

问题


Is this possible to programmatically open any file on disk using HTML5 File API, for example adding at first those paremeters?

open -a Chromium --args --allow-file-access-from-files --disable-web-security

回答1:


First you have to open Chrome using the flag --allow-file-access-from-files Make sure all your chrome windows are closed before opening it with the flag.

Then with javascript you have to use the XMLHttpRequest object. Something like this:

xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","file.txt",false);
xmlhttp.send();
var result = xmlhttp.responseText;

In result you will have the content of the file.

If it's an xml you can automatically parse it using

var xmlDom = xmlhttp.responseXML;

The file path has to be relative to the html file you are opening.



来源:https://stackoverflow.com/questions/16150593/opening-any-arbitrary-file-on-disk-using-html-file-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!