I need to read a file from the browser and I CANNOT use ajax.. it is necessary to be read locally..
this is not a duplicate from Reading a file using javascript
how can I do that?
ps: I also CANNOT use an engine like V8 http://code.google.com/p/v8/ I need to read it with the current native API from javascript!.. is there any way to do that?
ps2: it must run only with chrome, or firefox! IE and others doesnt matter
asked Feb 25, 2013 at 5:16
user1616355
-
Make use of iframe in HTML5EnterJQ– EnterJQ2013年02月25日 05:18:01 +00:00Commented Feb 25, 2013 at 5:18
-
Maybe an explanation of your limitations would help us suggest solutionsmplungjan– mplungjan2013年02月25日 05:20:21 +00:00Commented Feb 25, 2013 at 5:20
1 Answer 1
Here is the sample: DEMO
function readMultipleFiles(evt) {
//Retrieve all the files from the FileList object
var files = evt.target.files;
if (files) {
for (var i = 0, f; f = files[i]; i++) {
var r = new FileReader();
r.onload = (function (f) {
return function (e) {
var contents = e.target.result;
alert(contents);
};
})(f);
r.readAsText(f);
}
} else {
alert("Failed to load files");
}
}
document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false);
answered Feb 25, 2013 at 5:20
coder
13.2k32 gold badges116 silver badges221 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js