views:

186

answers:

1

Here is a little example: (live demo here)

HTML:

<input id="file" type="file" />

Javascript:

$(function() {
    $("#file").click();
});

In Firefox 3.6.6 nothing happens, while in IE7 the "Choose File" dialog box is opened.

Any ideas how to open the "Choose File" dialog box in Firefox without clicking on the Browse button ?

+3  A: 

The file-dialog breaks out of the sandbox your javascript code runs in (access to HDD). Good/secure browsers (= not IE7) should prevent that this dialog is opened via a script - it MUST be opened by a real mouseclick.

Some browsers seem to allow it, but it varies.

See more in In JavaScript can I make a “click” event fire programmatically for a file input element?

Marcel J.