Just for the record, there is an alternative solution that does not require javascript. It is a bit of a hack, exploiting the fact that clicking on a label sets the focus on the associated input.
You need a <label>
with a proper for
attribute (points to the input), optionnaly styled like a button (with bootstrap, use btn btn-default
). When the user clicks the label, the dialog opens, example :
<!-- optionnal, to add a bit of style -->_x000D_
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>_x000D_
_x000D_
<!-- minimal setup -->_x000D_
<label for="exampleInput" class="btn btn-default">_x000D_
Click me_x000D_
</label>_x000D_
<input type="file" id="exampleInput" style="display: none" />
_x000D_