I'd like to make a click event fire on an <input type="file">
tag programmatically.
Just calling click() doesn't seem to do anything or at least it doesn't pop up a file selection dialog.
I've been experimenting with capturing events using listeners and redirecting the event, but I haven't been able to get that to actually perform the event like someone clicked on it.
This worked for me:
Hey this solution works. for download we should be using MSBLOB
For AngularJS or even for normal javascript.
I was researching this a while ago because I wanted to create a custom button that would open the file dialog and start the upload immediately. I just noticed something that might make this possible - firefox seems to open the dialog when you click anywhere on the upload. So the following might do it:
This is only theoretical since I already used another method to solve the problem but it just might work.
For those who understand that you have to overlay an invisible form over the link, but are too lazy to write, I wrote it for you. Well, for me, but might as well share. Comments are welcome.
HTML (Somewhere):
HTML (Somewhere you don't care about):
JavaScript:
This code works for me. Is this what you are trying to do?
it's not impossible:
But somehow it works only if this is in a function which was called via a click-event.
So you might have following setup:
html:
JavaScript: