Skip to content

Instantly share code, notes, and snippets.

@tobychui
Created March 5, 2023 09:18
Show Gist options
  • Save tobychui/e3d5d3a5009c39ed0184a2a4dc43a28f to your computer and use it in GitHub Desktop.
Save tobychui/e3d5d3a5009c39ed0184a2a4dc43a28f to your computer and use it in GitHub Desktop.
Vanilla Javascript (JS) implementation of a file selection dialog that open and read local text files
let input = document.createElement('input');
input.type = 'file';
input.multiple = true;
input.onchange = e => {
let files = e.target.files;
for (var i = 0; i < files.length; i++){
let read = new FileReader();
read.readAsBinaryString(files[i]);
read.onloadend = function(){
//Content of the file selected
console.log(read.result);
}
}
}
input.click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment