Skip to content

Instantly share code, notes, and snippets.

@rahulbanerjee26
Created June 22, 2022 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulbanerjee26/9e0adc6a0a5114b2748a8f16a7a3857f to your computer and use it in GitHub Desktop.
Save rahulbanerjee26/9e0adc6a0a5114b2748a8f16a7a3857f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function readFromFile() {
const display = document.querySelector('.display');
const [file] = document.querySelector('input[type=file]').files;
const reader = new FileReader();
reader.addEventListener("load", () => {
// this will then display a text file
display.innerText = reader.result;
}, false);
if (file) {
reader.readAsText(file);
}
}
</script>
</head>
<body>
<input type="file" onchange="readFromFile()"><br>
<p class="display"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment