1const browseFiles = () => {
2 var input = document.createElement('input');
3 input.type = 'file';
4 input.click();
5}
1function readSingleFile(e) {
2 var file = e.target.files[0];
3 if (!file) {
4 return;
5 }
6 var reader = new FileReader();
7 reader.onload = function(e) {
8 var contents = e.target.result;
9 displayContents(contents);
10 };
11 reader.readAsText(file);
12}
13
14function displayContents(contents) {
15 var element = document.getElementById('file-content');
16 element.textContent = contents;
17}
18
19document.getElementById('file-input')
20 .addEventListener('change', readSingleFile, false);