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>
The problem is that FileReader
is not compatible with 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
But you can use a polyfill ! Moxie can solve your problem. https://github.com/moxiecode/moxie
IE 8 does not support FileReader
.
Try using modernizr . I guess you can get it working with it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.