Reputation: 1651
I´m trying to make an uploader with javascript. I basically have my input file:
<input id="attachments" type="file" style="display:none; float:left; margin-right:5px;" multiple="" name="file[]">
hidden so when i click a button i trigger my input like this:
$(thisELement).find("#attachments").trigger("click");
and finally i catch the onchage on my input like this:
$(thisELement).find("#attachments").change(function(e){
console.log(this.file);
For firefox and chrome, it works fine, but when i test it in IE 9 i get in the console "this.file" is undefined Does anyone knows why does IE doesn´t accept "this.file", and which instruction would be it´s equivalent?
Thanks in advance.
Upvotes: 0
Views: 289
Reputation: 11054
IE is notoriously tight on security when it comes to file uploads. It does not let you use JS to trigger file uploads since that may not involve a user interaction, and allow a page to "steal" files without the user knowing. I have researched this pretty extensively and the answer is pretty much that you just can't do it, you have to use the native file upload control.
You might try using the jquery plug-in uploadify. It uses Flash to get around this security restriction, but then you're stuck with their UI, instead of the browser's. However their UI does allow you some customization.
Upvotes: 1