Languages
[Edit]
EN

JavaScript - input file dialog closed event

10 points
Created by:
ArcadeParade
666

In this short article, we would like to show how for input file element, handle dialog closed event.

By default it is not possible to handle dialog close event in JavaScript. The solution presented in the article uses trick based on getting window focus back after file dialog is closed.

 

Focus based solution

Edit

The solution tracks window focus state and fires event when dialog is closed.

 

Delay based solution

Edit

This section contains improved above solution.

It tracks window focus state and fires delayed event when dialog is closed. That solution helps to solve problems related with multiple dialogs (one after the other), e.g. directory upload dialog with displayed additional warning dialog.

The example shows how to handle dialog closed event on directory selection input. Select some big directory to see the effect.

 

See also

Edit
  1. JavaScript - add event listener called only once

Alternative titles

  1. JavaScript - input file choicer closed event
  2. JavaScript - input file selector closed event
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join