Hello and welcome to our community! Is this your first visit?
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
    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:

    <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.innerHTML = fileLoadedEvent.target.result;

    Many thanks

  2. #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 619 Times in 599 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.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com


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