Skip to content

Instantly share code, notes, and snippets.

@morphIsmail
Created December 16, 2020 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save morphIsmail/6bbb59664bbbd72a796041896c53e201 to your computer and use it in GitHub Desktop.
Save morphIsmail/6bbb59664bbbd72a796041896c53e201 to your computer and use it in GitHub Desktop.
Чтение из файла на JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Чтение файла</title>
</head>
<body>
<input type="file" id="file">
<button>Чтение файла</button>
<script>
document.querySelector('button').addEventListener('click', function() {
let file = document.getElementById('file').files[0];
let reader = new FileReader();
reader.readAsText(file);
reader.onload = function() {
console.log(reader.result);
}
reader.onerror = function() {
console.log(reader.error);
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment