How can I programmatically open a file collector using JavaScript?

Possible duplicate:
In JavaScript, can I make the "click" event programmatically for a file input element?

I naively tried the following to open the program file collector using JavaScript (see script here ):

<input type='file'>

<script>
    $(function () {
        $('input').click();
    });
</script>

The above does not work. How to open input type='file'javascript file collector ?

+5
source share
2 answers

For security reasons, you cannot initiate a dialogue unless it is a response to some kind of user-initiated event. For example, you can call up a dialog by clicking on another element:

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

Working example .

+8
+5

All Articles