Created
May 25, 2021 04:14
-
-
Save yehgdotnet/05b3f63d3e8cfee0f6ad6312c60f027a to your computer and use it in GitHub Desktop.
Read local file using JavaScript
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
<!-- https://www.geeksforgeeks.org/how-to-read-a-local-text-file-using-javascript/ --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Read Text File</title> | |
</head> | |
<body> | |
<input type="file" name="inputfile" | |
id="inputfile"> | |
<br> | |
<pre id="output"></pre> | |
<script type="text/javascript"> | |
document.getElementById('inputfile') | |
.addEventListener('change', function() { | |
var fr=new FileReader(); | |
fr.onload=function(){ | |
document.getElementById('output') | |
.textContent=fr.result; | |
} | |
fr.readAsText(this.files[0]); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment