问题
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