Peter
Peter

Reputation: 21

Javascript FileReader on IE8

I have this javascript function which shows a preview after user picked an image. My problem is that it's not working on IE and I do not figure out why.

No error, but input.files is null.

The JavaScript

function showimagepreview(input, previewId) {
    if (input.files && input.files[0]) {
        var filerdr = new FileReader();
        filerdr.onload = function (e) {
            $('#' + previewId).attr('src', e.target.result);
        }
        filerdr.readAsDataURL(input.files[0]);
    }
}  

this is my HTML code

<div class="photo" id="photo-1">
    <input type="file" class="upload-file" name="Photos[1]" onchange="showimagepreview(this, 'photosPreview1')" />
    <img id="photosPreview1" class="PhotoPreview" />
</div>

Upvotes: 1

Views: 7108

Answers (3)

Yoann Gueny
Yoann Gueny

Reputation: 101

As explain previously IE 8 Doesn't support FileReader API http://caniuse.com/#feat=filereader

But you can use a polyfill ! Moxie can solve your problem. https://github.com/moxiecode/moxie

Upvotes: 1

nozzleman
nozzleman

Reputation: 9649

IE 8 does not support FileReader.

Try using modernizr. I guess you can get it working with it.

Upvotes: 0

Andy
Andy

Reputation: 4778

The problem is that FileReader is not compatible with IE8.

See here for a comprehensive list of browser support for this functionality.

Upvotes: 1

Related Questions