Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Чтение из файла на 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