Skip to content

Instantly share code, notes, and snippets.

@ctosib
Created December 31, 2016 05:55
Show Gist options
  • Save ctosib/921725b5b99c69b47314b88ae4e8c824 to your computer and use it in GitHub Desktop.
Save ctosib/921725b5b99c69b47314b88ae4e8c824 to your computer and use it in GitHub Desktop.
Use Javascript to read a text file
<html>
<head>
</head>
<body >
<input type='file' onchange='openFile(event)'><br>
<div id='output'>
</div>
<script>
var openFile = function(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
var text = reader.result;
var output = document.getElementById('output');
output.innerText = text;
};
reader.readAsText(input.files[0]);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment