0

I have input[type=file] with log-in form on it. So after user logged in - file upload dialog instantly opened.

In all browsers I need (FF, IE10+) except Google Chrome, this call works perfect:

$('input[type=file]').click();

or

$('input[type=file]')[0].click();

or

$('input[type=file]').trigger('click');

Did anyone met this problem? If so, how to achieve this on Chrome?

Edit1: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.click here in support it's said that I can use it on input[type=file]. Also this click is working, but only if I'll actually click something, that than is clicking my input(so only after physical click).

Edit2: And yes, I've already tried search function. But everything I've found was old, and pretty much anyone told, that even FF is not supporting this (which is not true now).

Edit3: Example test page: http://jsfiddle.net/Ux3t4/

David Mulder
  • 26,123
  • 9
  • 51
  • 114
Kamilius
  • 588
  • 14
  • 34

1 Answers1

1

This is not allowed due to security reasons. By the way, even in Internet Explorer (the dialog will be shown but once you select a file, the file won't be submitted).

SiZiOUS
  • 638
  • 1
  • 8
  • 9
  • Maybe it's not allowed for Chrome only? Because this works perfect on both FF and IE. Just tried, and all of my files were submited correctly. – Kamilius Jun 11 '14 at 11:49
  • 1
    @Kamilius FF trigger popup blocker you need to manually allow the popup. – Rahil Wazir Jun 11 '14 at 11:51
  • 1
    @Kamilius As far I remember you can't do this. I searched for a solution on Google and found some useful info there: http://stackoverflow.com/questions/4878164/input-file-click-chrome – SiZiOUS Jun 11 '14 at 12:04