John Kim
John Kim

Reputation: 1872

FileReader javascript class not working with IE

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

Upvotes: 0

Views: 4134

Answers (2)

Thomas Denney
Thomas Denney

Reputation: 1608

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.

Upvotes: 1

Norbert Orzechowicz
Norbert Orzechowicz

Reputation: 1311

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

Upvotes: 12

Related Questions