简体   繁体   English

IE8上的Javascript FileReader

[英]Javascript FileReader on IE8

I have this javascript function which shows a preview after user picked an image. 我有这个javascript函数,可在用户选择图像后显示预览。 My problem is that it's not working on IE and I do not figure out why. 我的问题是它无法在IE上运行,我也不知道为什么。

No error, but input.files is null. 没有错误,但是input.files为null。

The JavaScript 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 这是我的HTML代码

<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>

The problem is that FileReader is not compatible with IE8. 问题是FileReader与IE8不兼容。

See here for a comprehensive list of browser support for this functionality. 有关完整的浏览器支持功能列表,请参见此处

As explain previously IE 8 Doesn't support FileReader API http://caniuse.com/#feat=filereader 如前所述,IE 8不支持FileReader API http://caniuse.com/#feat=filereader

But you can use a polyfill ! 但是您可以使用polyfill! Moxie can solve your problem. Moxie可以解决您的问题。 https://github.com/moxiecode/moxie https://github.com/moxiecode/moxie

IE 8 does not support FileReader . IE 8不支持FileReader

Try using modernizr . 尝试使用modernizr I guess you can get it working with it. 我想您可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM