0

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
2
  • Make use of iframe in HTML5 Commented Feb 25, 2013 at 5:18
  • Maybe an explanation of your limitations would help us suggest solutions Commented Feb 25, 2013 at 5:20

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.