Created
August 7, 2017 08:10
-
-
Save tonY1883/fb6d39c852d17dba4799ebd63f273dc4 to your computer and use it in GitHub Desktop.
open a local file with js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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