Created
December 31, 2016 05:55
-
-
Save ctosib/921725b5b99c69b47314b88ae4e8c824 to your computer and use it in GitHub Desktop.
Use Javascript to read a text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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