Created
June 22, 2022 03:52
-
-
Save rahulbanerjee26/9e0adc6a0a5114b2748a8f16a7a3857f to your computer and use it in GitHub Desktop.
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
<!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