How can I programmatically open the file picker with JavaScript?

google-chrome, javascript

Solution

For security reasons you can't trigger the dialog, unless it is as a response to some user triggered event. You could for instance trigger the dialog through a click on some other element:

$(function () {
    $(".someElement").click(function () {
        $('#f').click();
    });
});

Working example.

Problem

Possible Duplicate: In JavaScript can I make a “click” event fire programmatically for a file input element? I have naively tried the following to open the file picker programmatically with JavaScript (see fiddle here): ``` <input type='file'>​ <script> $(function () { $('input').click(); }); </script> ``` The above doesn't work. How can I open the file picker of a `input type='file'` with JavaScript?

Original source

Related problems