Open file download dialog when clicked

I need to open the file download dialog by clicking on another button. I hide the file upload control (visibility: hidden) and when I press any other button I want to open this dialog. Below is the code I have:

<input type="file" style="visibility: hidden;" /> 

Below is javascript:

 $('#button').click(function() { $('input[type=file]').click(); }); 

It works fine in Firefox 4 and IE8, but it doesn't work in chrome12, so the dialog doesn't open. Any idea why?

+23
source share
3 answers

I tested the simple code asked in the question today, and the situation has changed:

  • IE9: works
  • Chrome23: works
  • Firefox15: works

There is only one IE for IE that performs blocking, but this is not the case in other browsers.

+8
source

In your example, the input file does not have an identifier, but you are trying to reference it with C # input. This works for me:

 $('#button').click(function() { $('input[type=file]').click(); }); 
+6
source

You should put the input [file] just above your custom control. And then tie it to it.

Also make it a larger font size, as only in this way you can increase its height.

0
source

Source: https://habr.com/ru/post/916038/


All Articles