2

The fileReader function read my txt file from the sdcard and the result will be set in the evt.target.result. I want to write (document.write) this evt.target.result to my html page. What is the best way to show this result on the screen. My filereader function:

function fileReader() 
{

    var reader = new FileReader(); 
    reader.onload = win; 
    reader.onerror= fail; 
    reader.readAsText("/sdcard/mytest.txt");

    function win(evt) 
    { 
        console.log(evt.target.result);
    } 

    function fail(evt) { 
        console.log(evt.target.error.code); 
    } 
};

1 Answer 1

2

You would need to have a div or something similar on your HTML page to display the result. There's tons of ways to present and style this, but the simplest would be to include the div in your HTML and reference it by id in your JS

<!DOCTYPE html>
<html>
  <body>
     <!-- Your results will display below -->
    <div id="results"></div>
  </body>
</html>

and in your JS do this

document.getElementById("results").innerHTML = evt.target.result;
1
  • 2
    You should mark my response as the answer then. Its kinda how this whole stackoverflow thing works ;) May 11, 2011 at 20:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.