I have not used JavaScript after a while, and I cannot read a text file and display the contents.
I tried onload as well as onloadend . If I just put reader.onload = alert('Hello'); , a warning is triggered, but I cannot get something to work with this function.
Not exactly where to go from here. I tried to define the function after reader.onload = function(evt)... but this will not work.
I also tried in Safari 6.0.5 and Chrome.
<!DOCTYPE HTML> <html> <head> <title>Pi to Colors</title> </head> <body> <script> function readFile() { var reader = new FileReader(); reader.onload = readSuccess; function readSuccess(evt) { var field = document.getElementById('main'); field.innerHTML = evt.target.result; }; reader.readAsText("/pi.txt"); } </script> <div id="main"> </div> </body> </html>
javascript html5
Cody b
source share