Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    .length issue in ie8 and 9

    Hi I am new to this forum.

    I have created a file upload base64 encoder where if a user uploads a document like .doc or .docx it converts it to base64 format onChange. It works fine in most browsers but I am having trouble with ie8 and ie9. In the ie debugger it generates an 'Unable to get property 'length' of undefined or null reference' error. Is there something I need to do specifically for ie9 and and lower?

    This is the code I am using:

    [CODE]
    <p>Select a File to Load:</p>
    <input id="inputFileToLoad" type="file" onChange="loadImageFileAsURL();" />
    <br />
    <p>File Contents as DataURL:</p>
    <textarea id="textAreaFileContents" style="width:640;height:240;" ></textarea>

    <script type='text/javascript'>
    function loadImageFileAsURL()
    {
    var filesSelected = document.getElementById("inputFileToLoad").files;
    if (filesSelected.length >0)
    {
    var fileToLoad = filesSelected[0];
    var fileReader = new FileReader();
    fileReader.onload = function(fileLoadedEvent)
    {
    var textAreaFileContents = document.getElementById
    (
    "textAreaFileContents"
    );
    textAreaFileContents.innerHTML = fileLoadedEvent.target.result;
    };
    fileReader.readAsDataURL(fileToLoad);
    }
    }
    </script>
    [CODE]

    Many thanks
    Craig

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    FileReader() wasn't introduced until IE10. If you want to use files in older copies of IE, you'll need to use a flash uploader or use an old-school form upload to put them on a server and then use ajax to get them back into JS land. There are some "stupid IE tricks" that can read certain files if conditions are just right, but these days those methods require changing security settings and should thus be avoided.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •