0

How can I trigger single click event in IE? It working fine in chrome and FF but not working in IE 8,9,10

My HTML :

<div class="qq-uploader">
    <div class="qq-upload-button"
        style="position: relative; overflow: hidden; direction: ltr;"
        id="sizcache07400451357324745">
        Click here to upload Image
        <input type="file" multiple="multiple" name="file" style="position: absolute; right: 0px; top: 0px; font-family: Arial; font-size: 450px; margin: 0px; padding: 0px; cursor: pointer; opacity: 0;">
    </div>
</div>

jQuery :

$(".qq-upload-button").each(function(){
   $(this).click(function(e){
     $(this).find('input[type="file"]').trigger('click');
     return false;
   });
}); 
Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
  • Input click trigger is inconsistent across browsers (http://stackoverflow.com/questions/210643/in-javascript-can-i-make-a-click-event-fire-programmatically-for-a-file-input). I'd suggest to replace .qq-upload-button div with label, so it'll trigger inner input. – Klaster_1 Нет войне Jan 20 '14 at 05:56

1 Answers1

1

You can't open fileupload dialog programmatically for a file input element in all browser. See this answer for more info.

It will be better to do it by force use click on file upload control.

Also you are adding handler to $(".qq-upload-button") in each loop, you can add handlers by on method at once:

$(".qq-upload-button").on('click', function(e){
    $(this).find('input[type="file"]').trigger('click');
});
Community
  • 1
  • 1
Alex
  • 11,115
  • 12
  • 51
  • 64
  • Sorry! it trigger click event but file upload dialog box does not open. why? – Sadikhasan Jan 20 '14 at 05:59
  • write html code in some other place try once. if it's working problem with css in ie else problem with js. i am not sure try once may be help you – Sarath Babu Nuthimadugu Jan 20 '14 at 06:11
  • I edit my answer. You can get more info from this [question and answers](http://stackoverflow.com/questions/210643/in-javascript-can-i-make-a-click-event-fire-programmatically-for-a-file-input). I also told you how to do more shorter you code example. – Alex Jan 20 '14 at 06:32
  • Sorry! I checked all possibility but id doesn't work. – Sadikhasan Jan 20 '14 at 06:46