简体   繁体   English

FileReader JavaScript类不适用于IE

[英]FileReader javascript class not working with IE

I'm using javascript FileReader class to preview the image prior to uploading it to the server. 我正在使用javascript FileReader类预览图像,然后再将其上传到服务器。 Everything seems to work fine with Firefox and Chrome but it does not seem to work with IE for some reason. 一切似乎都可以在Firefox和Chrome上正常运行,但由于某些原因似乎无法与IE一起运行。

Below is my code for it. 下面是我的代码。 (This is for Cakephp framework) (这是针对Cakephp框架的)

Is there a way we can fix this so it works in IE too? 有没有一种方法可以解决此问题,使其也可以在IE中使用?

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

在IE中,您应该使用ActiveXObject,因为IE不是浏览器

FileReader is a relatively new addition to JavaScript and because Internet Explorer is old it doesn't support it yet. FileReader是JavaScript的一个相对较新的功能,由于Internet Explorer较旧,因此尚不支持它。 Internet Explorer 7/8 doesn't support it at all and IE9 only has partial support for offline storage. Internet Explorer 7/8完全不支持它,而IE9仅部分支持离线存储。 Internet Explorer 10, however, is going to get early support. 但是,Internet Explorer 10将获得早期支持。 I would just stick a message on there for IE users telling them (politely, of course) to get a real browser. 我只是向IE用户发送一条消息,告诉他们(当然,要礼貌地)获得一个真正的浏览器。

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

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