FileReader javascript class not working with IE

2019-03-04 21:04发布

I'm using javascript FileReader class to preview the image prior to uploading it to the server. Everything seems to work fine with Firefox and Chrome but it does not seem to work with IE for some reason.

Below is my code for it. (This is for Cakephp framework)

Is there a way we can fix this so it works in IE too?

<script type="text/javascript">
            function imageBack(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.onload = function (e) {
                    $('#uploadBackImage').attr('src', e.target.result);
                    $('#cardbackImagePath').attr('value',e.target.result);
                }
                    reader.readAsDataURL(input.files[0]);
                }
            }
        </script>
<input type="file" name="data[Card][uploadBack]" class="file" onchange="imageBack(this);" width="240" height="150" id="CardUploadBack">

2条回答
爷的心禁止访问
2楼-- · 2019-03-04 21:17

In IE you should use ActiveXObject because IE is not a browser

查看更多
Anthone
3楼-- · 2019-03-04 21:28

FileReader is a relatively new addition to JavaScript and because Internet Explorer is old it doesn't support it yet. Internet Explorer 7/8 doesn't support it at all and IE9 only has partial support for offline storage. Internet Explorer 10, however, is going to get early support. I would just stick a message on there for IE users telling them (politely, of course) to get a real browser.

查看更多
登录 后发表回答