Is there any chance to detect every file selection the user made for an HTML input
of type file
element?
This was asked many times before, but the usually proposed onchange
event doesn't fire if the user select the same file again.
Set the value of the input
to null
on each onclick
event. This will reset the input
's value and trigger the onchange
event even if the same path is selected.
input.onclick = function () {
this.value = null;
};
input.onchange = function () {
alert(this.value);
};
Here's a DEMO.
Note: It's normal if your file is prefixed with 'C:\fakepath\'. That's a security feature preventing JavaScript from knowing the file's absolute path. The browser still knows it internally.