HTML 4 equivalent of HTML 5's FileReader?

后端 未结 3 1228
甜味超标
甜味超标 2020-12-09 23:08

I\'ve got a web page which needs to be able to load files into the DOM from the local machine on which the browser is running. I\'ve found that this is very easy to do using

3条回答
  •  春和景丽
    2020-12-09 23:40

    Further to the other answers here, it does appear that there's no consistent way of doing this client-side (other than Flash) for older browsers.

    For IE7/8 however, I've managed to hack something together using ActiveX.

    var filePath = f:\oo.txt;
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var textStream = fso.OpenTextFile(filePath);
    var fileData = file.ReadAll();
    

    I can then pass this to the same function as reader.onload in the question above. Obviously this is a bad, hacky solution, and liable to be blocked by some security policies - it does at least work for IE7 though!

提交回复
热议问题