mirror of https://bitbucket.org/ausocean/av.git
26 lines
719 B
JavaScript
26 lines
719 B
JavaScript
window.onload = function () {
|
|
document.getElementById('input').addEventListener('change', getFile)
|
|
}
|
|
|
|
function getFile(){
|
|
const input = event.target
|
|
if ('files' in input && input.files.length > 0) {
|
|
placeFileContent(document.getElementById('content'), input.files[0])
|
|
}
|
|
}
|
|
|
|
function placeFileContent(target, file) {
|
|
readFileContent(file).then(content => {
|
|
target.value = content
|
|
}).catch(error => console.log(error))
|
|
}
|
|
|
|
function readFileContent(file) {
|
|
const reader = new FileReader()
|
|
return new Promise((resolve, reject) => {
|
|
reader.onload = event => resolve(event.target.result)
|
|
reader.onerror = error => reject(error)
|
|
reader.readAsText(file)
|
|
})
|
|
}
|