Skip to content

Instantly share code, notes, and snippets.

@tonY1883
Created August 7, 2017 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonY1883/fb6d39c852d17dba4799ebd63f273dc4 to your computer and use it in GitHub Desktop.
Save tonY1883/fb6d39c852d17dba4799ebd63f273dc4 to your computer and use it in GitHub Desktop.
open a local file with js
function loadFile(type) {
var fileSelector = $('<input type="file">');
if (type) {
fileSelector.attr('accept', type);
}
fileSelector.change(function () {
var file = fileSelector[0].files[0];
fname = file.name;
var reader = new FileReader();
reader.onload = function (e) {
var contents = e.target.result;
loadData(contents);
};
reader.readAsText(file);
});
fileSelector.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment