Event to cancel file upload in javascript

We can use file.onchange if we are going to set the callback to read the file using javascript, but how to set the event when the user cancels the download (close the browse panel)?

+6
source share
3 answers

There is no API for the input modal file. Also, if the user closes the browser, will your code no longer run?

Of course, there is a window.onunload method that allows you to define the example you are giving.

In the comments, the best I can think of would be useful, since if nothing is selected, file.value.length will be 0 .

+1
source

no browser support for "onfileopendialogboxclose" or "onfileselectioncancel". plus the file selection dialog is not an element and cannot be selected as an html element

0
source

It is very simple with jQuery:

 $("#fileInputId").change(function () { //implement your code here }); 
-3
source

Source: https://habr.com/ru/post/920382/


All Articles