I\'m playing with JavaScript and wrote simple function that creates INPUT
element (type=\"file\"
) and simulates click.
var createAn
I know this question was not about a workaround, but I came here looking for a solution. This worked for me on Chrome. I have simply moved let input
outside the function. This works because (as suggested by bside) it prevents input
from being garbage collected. I only expect to have one open-file dialog open at a time so the singleton pattern is OK here.
let input;
var createAndCallFileSelect = function () {
input = document.createElement ("input");
input.setAttribute ("type", "file");
input.addEventListener ("change", function () {
console.log (this.files);
}, false);
input.click();
}