How to get input file in IE when changing

I need to upload a file to upload. This code works in chrome, opera and firefox, but not with IE:

$("input:file").change(function () { // Get a reference to the fileList var files = !!this.files ? this.files : []; // If no files were selected, or no FileReader support, return if ( !files.length || !window.FileReader ) return; // Only proceed if the selected file is an text if ( /^text/.test( files[0].type ) ) { var reader = new FileReader(); reader.readAsText( files[0] ); reader.onloadend = function() { restoreCSS(this.result); } } } 

In IE !!this.files returns false. Thanks for the promotion.

+4
source share
1 answer

What version of IE are you using? FileReader not supported in IE prior to version 10 .

As @apsillers commented, there is another question about how to imitate FileReader support in browsers that don't support it . I believe that they all require some kind of plug-in (Flash / Silverlight), as before the FileReader API, JavaScript had no access to the file system.

+1
source

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


All Articles