142
rated 0 times
[
149]
[
7]
/ answers: 1 / hits: 37310
/ 9 Years ago, tue, june 2, 2015, 12:00:00
I would like to modify this code so that it works with a specific file only, but I can't figure out the correct URL parameter and all the code examples that I've found use a file selection dialog.
<!DOCTYPE html>
<html>
<head>
<title>reading file</title>
<script type=text/javascript>
var reader = new FileReader();
function readText(that){
if(that.files && that.files[0]){
var reader = new FileReader();
reader.onload = function (e) {
var output=e.target.result;
//process text to show only lines with @:
output=output.split(n).filter(/./.test, /@/).join(n);
document.getElementById('main').innerHTML= output;
};//end onload()
reader.readAsText(that.files[0]);
}//end if html5 filelist support
}
</script>
</head>
<body>
<input type=file onchange='readText(this)' />
<div id=main></div>
</body>
Why doesn't it work when I change the code from:
<body>
<input type=file onchange='readText(this)' />
<div id=main></div>
</body>
to:
<body onload=readText('file:///C:/test.txt')>
<div id=main></div>
</body>
More From » filereader