问题
I have a input field with the type=file
to select an image file but what I want is that if someone opens the file selector dialog and on some particular event it automatically / programmatically closes the dialog without hitting the cancel button by the user. Is there any way to do it with js/jquery?
回答1:
Interaction with <input type="file" />
is very limited. There is no way to close the file dialog programmatically. You could potentially try to disable the drag/drop functionality while the dialog is open by handling the click
event; however, it seems that there is no reliable cross-browser method for determining that the dialog has been closed in a case where the user clicks cancel, so re-enabling it may be tricky.
Unfortunately, you will likely just have to let the user close the file dialog on their own if they choose to drag/drop files from it instead of using the "open" button.
回答2:
I think the answer to this is no. A file input change event opens a native browser window, this cannot be controlled using Javascript.
来源:https://stackoverflow.com/questions/53125427/how-to-programmatically-close-select-file-dialog