Here’s an example using the file input element and FileReader(): File Input test
HTML:
JS:
- var fileContents = document.getElementById('file-contents');
- var fileInput = document.getElementById('file-input');
- var reader = new FileReader();
- reader.addEventListener('load', (ev)=>{
- fileContents.value = ev.target.result;
- });
- fileInput.addEventListener('change', (ev)=>{
- reader.readAsText(ev.target.files[0])
- });
This is a good purely client-side solution if you’re trying to read client-side files in the browser. Si desea publicar el contenido …