How to programmatically close select file dialog

久未见 提交于 2021-01-29 01:40:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!