2

I have stuck on Mac browsers where I can not click file tag via jQuery .

Note : All this things are working fine on all OS browser.

I have one select box that has some values :

<input id="uploadedFile" style="position:absolute;top: -200px;" type="file">

<select id="user_avatar" original-title="Avatar">
  <option value="4" selected="selected">Female avatar</option>
  <option value="3">Male avatar</option>
  <option value="2">Upload your pic</option>
</select>

And using below Javascript to open file tag

$("#user_avatar").change(function() {
  if ( $(this).val() == "2") {
    $('#uploadedFile').click();
  }
});

I have debug lot on stackoverflow and other source. like :

But none was helping me to get out of this problem.

Guys If you have any idea to solve this issue the please please let me know.

Community
  • 1
  • 1
Vik
  • 5,931
  • 3
  • 31
  • 38
  • Is this happing to all browsers on Mac ? – prakashpoudel Jun 19 '13 at 16:26
  • Things are working fine into Firefox but Chrome and safari get stuck to me . – Vik Jun 19 '13 at 16:28
  • 1
    This is a "known" issue for years. Only some browsers and some versions support clicking `input[type=file]`. It's an old security issue. Your best bet is to use an "alternate" solution. Check out my solution to this [***here***](http://stackoverflow.com/questions/210643/in-javascript-can-i-make-a-click-event-fire-programmatically-for-a-file-input#answer-12826822) – SpYk3HH Jun 19 '13 at 16:31
  • Thanks SpYk3HH ,Yes I know such alternates but I am hoping that into this 1 year some better solution has generated . Hoping for that :) – Vik Jun 19 '13 at 16:35
  • 1
    @Vik Unfortunately, as aforementioned, this is considered a security issue, thus many browsers will not allow `.click` on `input[type=file]`. You're only choice is a custom solution. – SpYk3HH Jun 19 '13 at 17:46
  • Thanks SpYk3HH... I will implement it. – Vik Jun 20 '13 at 06:40

0 Answers0