2
使用HTML5文件API我已經創建了一種機制,供用戶從他的計算機中選擇一個文件,然後將其讀取爲字符串並在應用程序中處理。但是,該代碼在IE9中不起作用,所以我正在尋找一種解決方案。這是我的代碼,它創建了一個文件讀者對象:在IE9中以字符串形式讀取用戶指定的文件
function CreateFileReader(element)
{
var self=this;
// create an input field and insert it into the document
this.element=element;
this.element.html('');
var fileBox=$('<input type="file"/>');
this.element.append(fileBox);
// when the contents (file) of the fileBox change, read the file
this.fileBox.change(function() {
if (this.files.length > 0){
if (this.files[0]!=undefined) {
var file=this.files[0];
// set up the file reader
var reader = new FileReader();
reader.file=file;
// specify what happens when the file is loaded
reader.onloadend = self.processFile;
// read the file as a text string
reader.readAsText(file);
}
}
});
}
CreateFileReader.prototype.processFile = function(e) {
// if the file was loaded successfully
if (e.target.error==null && e.target.readyState==2) {
var fileString=e.target.result;
// do some stuff with fileString here
}
}
我會很感激,如果你能表明,IE9的工作方案。
相關:http://stackoverflow.com/questions/5397991/html-4-equivalent-of-html-5s-filereader和http ://stackoverflow.com/questions/5055724/flash-alternative-for-filereader-html-5-api – HoLyVieR