input type=file onchange not working on any version and button onclick not working on ie 9 for prototype.js

StackOverflow https://stackoverflow.com/questions/21449923

  •  04-10-2022
  •  | 
  •  

سؤال

I am trying to show the size of file to user as so as they select file before uploading onchange is working fine on Firefox and Google Chrome but doesn't get triggered on IE 8,9,10 version .I have even tried achieve this by giving button onclick of that it will show the size of file but again it is not working on IE 8,9 version it only works on IE 10 and above version(onclick event).

<input type="file" name="subjective_test_paper[source_upload]" id="source_upload" onChange="showFileSize();code_save_in_proper_file();" />

function showFileSize()
{

    input_file = $('source_upload')

    if (input_file.files.length > 0)
    {  

        file_size = input_file.files[0].size/1024
        file_size = Math.round(file_size * 10000) / 100
        $('show_text').innerHTML = file_size + " Kbytes"
    }
    else
    {
        $('show_text').innerHTML = " "
    }

}

Thanks in advance for help.

هل كانت مفيدة؟

المحلول

The ability to know what the file size and anything about the actual file that is selected is part of the HTML5 File API. Unfortunately before IE 10, Internet Explorer did not support the File API much less many HTML5 features (partly because IE 8 has been around since 2009)

TL;DR

This cannot be done in Internet Explorer 8, 9 - partial support in IE 10.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top